如果切换到新版本的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>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)...MainClass
@SpringBootApplication
@ComponentScan(value = "de.xyzs.microservice")
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class MainClass {
public static void main(String[] args) {
SpringApplication.run(MainClass.class, args);
}
}发布于 2017-03-22 15:32:20
我能够通过显式声明适用于1.4.4版本的云上下文依赖来解决这个问题。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>1.1.8.RELEASE</version>
</dependency>发布于 2016-10-27 05:30:42
在使用Spring 1.4.1 working时,他们将其更改为
new SpringApplicationBuilder().showBanner()
至
new SpringApplicationBuilder().bannerMode(Banner.Mode bannerMode)
Banner.Mode bannerMode需要一个枚举的位置:控制台、日志或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如果您正在寻找要打印的横幅,请使用第一个标题,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文档:
下面是解释Banner.Mode Enum的java文档:
http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/Banner.Mode.html
发布于 2018-01-18 08:32:44
在建立虚拟的生产者-消费者微型服务时,我也遇到了同样的问题。
在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>https://stackoverflow.com/questions/40258498
复制相似问题