NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder

缘起:

        初学spring cloud的朋友可能不知道,其实SpringBoot与SpringCloud需要版本对应,否则可能会造成很多意料之外的错误,比如eureka、nacos注册了结果找不到服务类啊,比如某些jar导入不进来啊,等等这些错误。下面列出来springBoot和spring cloud的版本对应关系,需要配套使用,才不会出现各种奇怪的错误

关于maven仓库的版本列表:

spring-cloud-dependencies 版本列表可查看:
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies
spring-boot-starter-parent 版本列表可查看:
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent

版本对应关系

大版本对应:

在实际开发过程中,我们需要更详细的版本对应:


 事情原由:

       在搭建一个基础项目的时候想集成一下nacos,于是查阅资料配置了相关的依赖和一些准备工作,在觉得一切做好重新启动项目的时候,遇到了下面的问题,经查询发现应该是springboot与springcloud版本依赖不兼容的问题

18:01:20.537 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
18:01:20.541 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
18:01:20.542 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/D:/test/springboot-mybatis-swagger/target/classes/]
18:01:20.650 [restartedMain] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/D:/test/springboot-mybatis-swagger/target/classes/]
18:01:20.653 [restartedMain] ERROR org.springframework.boot.SpringApplication - Application startup failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Class;)V
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:170)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70)
	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:122)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
	at com.example.demo.DemoApplication.main(DemoApplication.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

Process finished with exit code 0

 通过对比找到兼容的版本,然后启动项目后控制台提示no server available

看下我的bootstrap.yml文件

spring:
  application:
    name: nacos-demo
  cloud:
    nacos:
      config:
        server-addr: localhost:8848
        namespace: 8d05309a-28b6-4db2-bcec-19dc585d835b
        group: kayak_demo
        file-extension: yml
        refresh-enabled: true
#        prefix: test
      discovery:
        server-addr: localhost:8848
        namespace: 8d05309a-28b6-4db2-bcec-19dc585d835b
        group: kayak_demo

注意一个是discovery,另一个是config,当控制台输出报错信息为no server available时很可能为此项配置错误。我这里就是因为忘记添加discovery配置,加上之后就可以正常启动,并注册上去了


版权声明:本文为u013332981原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。