微服务踩坑之NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.问题的解决

由于SpringCloud的运行需要依赖SpringBoot,之前SpringBoot版本采用的是1.5.9.RELEASE版,SpringCloud采用的是Camden.SR5版,可以完美配合.今天突然把SpringBoot升级到2.0.3,然后SpringCloud版本还是Camden.SR5版本,如果报了如下异常:

NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Obje

[2019-07-10 11:26:02.002] [org.hibernate.validator.internal.util.Version] [background-preinit] [21] [INFO ] HV000001: Hibernate Validator 6.0.14.Final
[2019-07-10 11:26:03.003] [org.springframework.boot.SpringApplication] [main] [858] [ERROR] Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Object;)V
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.yudainxx.springBootDemo.SpringBootDemoApplication.main(SpringBootDemoApplication.java:29)

原因就是因为SpringBoot和SpringCloud版本不匹配,SpringBoot2.0.3版本,对应的SpringCloud的版本可以用Finchley.RELEASE版.

查看官网目前最新的Finchley版本是Finchley.M8,所以对于使用Spring Boot2.0.x的朋友,需要将对应的Spring Cloud切换为Finchley.M8版本,即可解决SpringApplicationBuilder.报出NoSuchMethodError的问题。下面给出大家一个spring boot版本和spring cloud版本的匹配关系:

微服务踩坑之NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.问题的解决_第1张图片

需要按照上述表格做Spring boot和Spring cloud的关系匹配,就不会出现该错误了.

你可能感兴趣的:(微服务,SpringCloud)