1.3.7.RELEASE -> 1.4.1.RELEASE | java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.showB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40258498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
1.3.7.RELEASE -> 1.4.1.RELEASE | java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.showBanner
提问by Steven Hachel
If I switch to the new version of SpringBoot, I get the above error message when starting the application. Why is that?
如果我切换到新版本的SpringBoot,启动应用程序时出现上述错误信息。这是为什么?
Best wishes Steven
最好的祝福史蒂文
pom.xml
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);
}
}
回答by Bwvolleyball
When working with Spring Boot 1.4.1.RELEASE, they have changed it from
使用 Spring Boot 1.4.1.RELEASE 时,他们已将其从
new SpringApplicationBuilder().showBanner()
new SpringApplicationBuilder().showBanner()
to
到
new SpringApplicationBuilder().bannerMode(Banner.Mode bannerMode)
new SpringApplicationBuilder().bannerMode(Banner.Mode bannerMode)
where Banner.Mode bannerMode
expects an enum for either: Console, Log, or Off.
其中Banner.Mode bannerMode
需要一个枚举:Console、Log 或 Off。
examples:
例子:
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
If you are looking for the banner to be printed, go with the first one, Banner.Mode.CONSOLE
如果您正在寻找要打印的横幅,请选择第一个, Banner.Mode.CONSOLE
Your new main method would look like this:
您的新 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.)
}
Here is the java doc to the SpringApplicationBuilder:
这是 SpringApplicationBuilder 的 java 文档:
And here is the java doc explaining the Banner.Mode
Enum:
这是解释Banner.Mode
枚举的java doc :
http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/Banner.Mode.html
http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/Banner.Mode.html
回答by Diogo Peixoto Martinez
Check out your Cloud dependencies. I had the same problem and just organize my cloud dependencies goes well. If you dont use cloud, just exclude cloud transitive dependencies from pom.
检查您的云依赖项。我遇到了同样的问题,只是组织我的云依赖关系很顺利。如果你不使用云,只需从 pom 中排除云传递依赖。
回答by Suresh nithyanandam
I was able to resolve this by explicitly declaring the cloud-context dependency which works for version 1.4.4
我能够通过显式声明适用于 1.4.4 版的云上下文依赖项来解决此问题
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
<version>1.1.8.RELEASE</version>
</dependency>
回答by rahulnikhare
I was also getting the same problem while setting up dummy Producer- consumer microservice.
在设置虚拟生产者-消费者微服务时,我也遇到了同样的问题。
Adding below changes in Pom.xml ,was able to solve my problem.
在 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>
回答by Arvind Kumar
I was also facing the same problem in maven based project while testing the demo for JWT project.
在测试 JWT 项目的演示时,我在基于 maven 的项目中也遇到了同样的问题。
I just removed the version from dependency like below-
我刚刚从依赖项中删除了版本,如下所示-
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
by doing this maven dependency resolver takes the default supported version.
通过这样做,Maven 依赖项解析器采用默认支持的版本。
Earlier I was mentioning version 2.1.3.RELEASEexplicitly which caused issue and then I removed the version then it took by default 2.0.3.RELEASEand worked for me.
早些时候我明确提到了2.1.3.RELEASE版本,它导致了问题,然后我删除了该版本,然后默认使用2.0.3.RELEASE并为我工作。
Issue resolved. !!!!!!!!!!!!!!!!!
问题解决了。!!!!!!!!!!!!!!!!!!
回答by Madhu
You get different errors if you use incompatible versions of libraries. So, before doing any troubleshooting, check the versions and make sure to use the compatible versions.
如果使用不兼容的库版本,则会出现不同的错误。因此,在进行任何故障排除之前,请检查版本并确保使用兼容的版本。
You can refer the below link to check what versions are compatible.
您可以参考以下链接来检查兼容的版本。
http://start.spring.io/actuator/info
http://start.spring.io/actuator/info
Got this link from one of the SO answers itself: Is there a compatibility matrix of Spring-boot and Spring-cloud?
从 SO 答案之一中获得了此链接:Is there a compatible matrix of Spring-boot and Spring-cloud?