一、Spring cloud 与spring boot 版本兼容

1、生产环境如何选择

坚决不用非稳定版本/end-of-life版本
尽量用最新一代

  • xxx.RELEASE版本可以官网一下
  • SR2之后可一般大规模使用

2、spring cloud与spring boot 版本兼容

可以查看官网
https://spring.io/projects/spring-cloud

在这里插入图片描述

HoxtonGreenwichFinchley 等 每个细版本可查看github
https://github.com/spring-projects/spring-cloud

3、整合

pom中添加

<dependencyManagement>
   <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

//修改spring boot为对应的版本
<dependencies>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>2.0.6.RELEASE</version>
         <type>pom</type>
         <scope>import</scope>
     </dependency>
     <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
</dependencies>

二、题外,由于jar包依赖引起的spring cloud项目报错

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method ‘httpPutFormContentFilter’ threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.ObjectMapper

spring boot版本:2.0.6.RELEASE
spring cloud版本:Finchley.SR2

引入了spring-cloud-starter-netflix-hystrix依赖后,就报上面错误 ,很明显是因为jackson-databindjar包冲突。
于是在spring-cloud-starter-netflix-hystrix依赖下,排除冲突jar如下:

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
   <!--排除冲突依赖,解决启动报错-->
   <!--Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.databind.ObjectMapper-->
   <exclusions>
       <exclusion>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-annotations</artifactId>
       </exclusion>
       <exclusion>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-core</artifactId>
       </exclusion>
       <exclusion>
           <groupId>com.fasterxml.jackson.core</groupId>
           <artifactId>jackson-databind</artifactId>
       </exclusion>
   </exclusions>
</dependency>

可以正常重启

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐