【问题标题】:1.3.7.RELEASE -> 1.4.1.RELEASE | java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.showBanner1.3.7.RELEASE -> 1.4.1.RELEASE | java.lang.NoSuchMethodError:org.springframework.boot.builder.SpringApplicationBuilder.showBanner
【发布时间】:2017-03-08 14:19:08
【问题描述】:

如果我切换到新版本的 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)...

主类

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

public class MainClass {

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

【问题讨论】:

  • 请添加更多详细信息。
  • 嗯,异常信息很清楚......你觉得NoSuchMethodError 是什么? ...
  • 我已经添加了“pom.xml”文件。 :-)

标签: java spring-boot


【解决方案1】:

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

您可以参考下面的链接来检查哪些版本是兼容的。

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

从其中一个 SO 答案中获得此链接:Is there a compatibility matrix of Spring-boot and Spring-cloud?

【讨论】:

    【解决方案2】:

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

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

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

    通过这样做,maven 依赖解析器采用默认支持的版本。

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

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 通过设置另一个属性解决了这个问题 - THX :-)
      【解决方案4】:

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

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

      【讨论】:

      【解决方案5】:

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

      【讨论】:

        【解决方案6】:

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

        您的新 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.)
        }
        

        这是 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 枚举的 java 文档:

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

        【讨论】:

        • 我如何影响这个?我只想使用当前版本的 Spring ...
        • 我编辑了答案以显示您的主要方法的外观。您不需要将 SpringApplicationBuilder() 的结果存储在变量中,我只是将它放在那里向您展示如何完成。
        • @Bwvolleyball,你能帮忙解决这个问题吗? stackoverflow.com/q/57393814/3301316
        猜你喜欢
        • 1970-01-01
        • 2017-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-24
        • 2018-10-22
        • 2015-11-03
        • 2015-06-01
        相关资源
        最近更新 更多