java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplication 版本兼容

错误如下:

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:74) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358) at org.springframework.boot.SpringApplication.run(SpringApplication.java:317) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) at demo.ms.robossliu.demo.DemoApplication.main(DemoApplication.java:14)

背景:

原springboot 2.x.x 一切正常,但是 整合 springCloud  添加了 spring cloud Edgware.SR3版本依赖 后启动报错如上

启动类如下:

@SpringBootApplication
@ComponentScan(basePackages={"com.xxx.xxxx"})
@MapperScan("com.xxx.xxx.mapper")
@EnableScheduling
public class TestApplication  extends SpringBootServletInitializer  {
    public static void main(String[] args)  {
        SpringApplication.run(CrawlerStockApplication.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
        return builder.sources(CrawlerStockApplication.class);
    }
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}

原因:

spring boot 2.0.0版本,spring cloud使用是Edgware.SR3版本,Edgware.SR3版本依赖于spring boot 1.5.x。看来是这两个组件的版本发生了冲突,所以解决方法也比较简单:1.降级spring boot版本,2.升级spring cloud版本。于是果断选择升级spring cloud至最新版本Finchley。更改pom SpringCloud 版本如下:


    
        
            org.springframework.cloud
            spring-cloud-dependencies
            Finchley.BUILD-SNAPSHOT
            pom
            import
        
    

 

 

 

你可能感兴趣的:(java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplication 版本兼容)