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

时间:2016-10-26 09:28:33

标签: 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>

堆栈跟踪

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)...

MainClass

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

public class MainClass {

    public static void main(String[] args) {
        SpringApplication.run(MainClass.class, args);
    }
}

6 个答案:

答案 0 :(得分:4)

使用Spring Boot 1.4.1.RELEASE时,他们已经从

更改了它

new SpringApplicationBuilder().showBanner()

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

其中Banner.Mode bannerMode需要枚举:控制台,日志或关闭。

的示例:

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

如果您要查找要打印的横幅,请使用第一个横幅Banner.Mode.CONSOLE

您的新主要方法如下所示:

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.)
}

以下是SpringApplicationBuilder的java文档:

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

以下是解释Banner.Mode Enum:

的java文档

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

答案 1 :(得分:4)

我能够通过明确声明适用于1.4.4版本的云上下文依赖来解决这个问题。

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-context</artifactId>
        <version>1.1.8.RELEASE</version>
    </dependency>

答案 2 :(得分:2)

在设置虚拟生产者 - 消费者微服务时,我也遇到了同样的问题。

在Pom.xml中添加以下更改,能够解决我的问题。

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

答案 3 :(得分:0)

查看您的云依赖项。我有同样的问题,只是组织我的云依赖顺利。 如果你不使用云,只需从pom中排除云传递依赖。

答案 4 :(得分:0)

在测试JWT项目的演示时,我在基于Maven的项目中也遇到了相同的问题。

我刚刚从如下所示的依赖项中删除了该版本

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
</dependency>

通过执行此Maven依赖解析程序,将采用默认的受支持版本。

之前,我曾明确提到过引起问题的版本 2.1.3.RELEASE ,然后我删除了该版本,然后默认使用了 2.0.3.RELEASE 并为我。

问题已解决。 !!!!!!!!!!!!!!!!!!!!

答案 5 :(得分:0)

如果使用不兼容版本的库,则会出现不同的错误。因此,在进行任何故障排除之前,请检查版本并确保使用兼容版本。

您可以通过下面的链接查看兼容的版本。

http://start.spring.io/actuator/info

从其中一个SO本身获得以下链接:Is there a compatibility matrix of Spring-boot and Spring-cloud?