2016-10-26 63 views
5

如果我切换到新版本的SpringBoot,当启动应用程序时,我得到上述错误信息。 这是为什么?1.3.7.RELEASE - > 1.4.1.RELEASE | java.lang.NoSuchMethodError:org.springframework.boot.builder.SpringApplicationBuilder.showBanner

祝 史蒂芬

的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); 
    } 
} 
+0

请填写更多详情。 –

+0

那么这个异常消息是非常清晰的......你有什么'NoSuchMethodError'是什么? ... –

+0

我已经添加了“pom.xml”文件。 :-) –

回答

3

当春天启动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-

这里是Java文档解释Banner.Mode枚举:

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

+0

我该如何影响呢?我只想使用当前版本的Spring ... –

+0

我编辑了答案,以显示您的主要方法的样子。您不需要将SpringApplicationBuilder()的结果存储在一个变量中,我只是简单地将它放在那里以向您展示如何完成这些工作。 – Bwvolleyball

+0

这不适合我。 – jDub9

0

检查出你的云依赖性。我有同样的问题,只是组织我的云依赖关系进展顺利。 如果您不使用云,只需从云中排除云传递依赖关系。

2

我能够明确地宣布云方面的依赖,其适用于1.4.4版

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

thx!有用! :-) –

+0

这工作。谢谢! – jDub9

0

我也得到了同样的问题而设立的虚拟生产者 - 消费者的microService解决这个问题。

在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>