1.3.7.RELEASE - > 1.4.1.RELEASE | java.lang.NoSuchMethodError:org.springframework.boot.builder.SpringApplicationBuilder.showBanner

Ste*_*hel 8 java spring-boot

如果我切换到新版本的SpringBoot,我在启动应用程序时会收到上述错误消息.这是为什么?

祝愿史蒂文

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.xyz.microservice</groupId>
<artifactId>spring-boot-test</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <!--version>1.3.7.RELEASE</version-->
    <version>1.4.1.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

</project>
Run Code Online (Sandbox Code Playgroud)

Stacktrace:

Exception in thread "main" java.lang.NoSuchMethodError:
                   org.springframework.boot.builder.SpringApplicationBuilder.showBanner(Z)Lorg/springframework/boot/builder/SpringApplicationBuilder;
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:109)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:75)...
Run Code Online (Sandbox Code Playgroud)

MainClass:

@SpringBootApplication
@ComponentScan(value = "de.xyzs.microservice")
@EnableAspectJAutoProxy(proxyTargetClass = true)

public class MainClass {

    public static void main(String[] args) {
        SpringApplication.run(MainClass.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

我可以通过明确声明适用于1.4.4版的云上下文依赖关系来解决此问题

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-context</artifactId>
        <version>1.1.8.RELEASE</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

  • 这不适用于2.0.2.RELEASE (5认同)

Bwv*_*all 4

当使用 Spring Boot 1.4.1.RELEASE 时,他们已将其从

new SpringApplicationBuilder().showBanner()

new SpringApplicationBuilder().bannerMode(Banner.Mode bannerMode)

其中Banner.Mode bannerMode需要一个枚举:Console、Log 或 Off。

例子:

new SpringApplicationBuilder().bannerMode(Banner.Mode.CONSOLE); //Prints banner to System.out

new SpringApplicationBuilder().bannerMode(Banner.Mode.LOG); //Prints banner to the log file

new SpringApplicationBuilder().bannerMode(Banner.Mode.OFF); //Disables the banner
Run Code Online (Sandbox Code Playgroud)

如果您正在寻找要打印的横幅,请选择第一个,Banner.Mode.CONSOLE

您的新 main 方法将如下所示:

public static void main(String[] args){

    //SpringApplicationBuilder() returns an ApplicationContext, but creating the variable is optional
    ApplicationContext ctx = new SpringApplicationBuilder().bannerMode(Banner.Mode.CONSOLE).run(args);

    //Now, if you need to do something else with the ApplicationContext, you can (such as print all the beans, etc.)
}
Run Code Online (Sandbox Code Playgroud)

这是 SpringApplicationBuilder 的 java 文档:

http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/builder/SpringApplicationBuilder.html#bannerMode-org.springframework.boot.Banner.Mode-

这是解释Banner.ModeEnum 的 java 文档:

http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/Banner.Mode.html