spring boot 2.0.0因为版本不匹配致使的NoSuchMethodError问题解析

spring boot升级到2.0.0之后,项目忽然报出 NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init> 异常,

跟踪源代码无果的状况下。忽然想到有多是spring boot 和 spring cloud版本不匹配致使的。
因而,上官网看spring cloud的依赖,首先看Edgware.SR2版本的依赖,能够看出Edgware.SR2依赖是1.5.X版本spring

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
</parent>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Edgware.SR2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

再看Finchley版本的依赖,能够看出Finchley依赖的是2.0.0版本spring-boot

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
</parent>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.BUILD-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

查看官网目前最新的Finchley版本是Finchley.M8,因此对于使用spring boot2.0.0的朋友,只要将对应的spring cloud切换为Finchley.M8版本,便可解决SpringApplicationBuilder.<init>报出NoSuchMethodError的问题。下面给出你们一个spring boot版本和spring cloud版本的匹配关系:ui

Spring Cloud Spring Boot
Finchley 兼容Spring Boot 2.0.x,不兼容Spring Boot 1.5.x
Dalston和Edgware 兼容Spring Boot 1.5.x,不兼容Spring Boot 2.0.x
Camden 兼容Spring Boot 1.4.x,也兼容Spring Boot 1.5.x
Brixton 兼容Spring Boot 1.3.x,也兼容Spring Boot 1.4.x
Angel 兼容Spring Boot 1.2.x

只要按照上述表格作spring boot和spring cloud的关系匹配,就不会出现该报错了。code

相关文章
相关标签/搜索