有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

1.3.7.发布>1.4.1。发布| java。lang.NoSuchMethodError:org。springframework。靴子建设者SpringApplicationBuilder。展示横幅

如果切换到新版本的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) 个答案

  1. # 1 楼答案

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

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

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

    通过执行此操作,maven依赖项解析器将采用默认支持的版本

    前面我提到了版本2.1.3。明确发布导致问题的版本,然后我删除了该版本,默认情况下采用了2.0.3。发布并为我工作

    问题解决了。 !!!!!!!!!!!!!!!!!

  2. # 2 楼答案

    我能够通过显式声明适用于1.4.4版的云上下文依赖关系来解决这个问题

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-context</artifactId>
            <version>1.1.8.RELEASE</version>
        </dependency>
    
  3. # 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>
    
  4. # 5 楼答案

    使用弹簧靴1.4.1时。释放,他们已经从

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

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

  5. # 6 楼答案

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