解决springboot与springcloud版本兼容问题(附版本兼容表)

 更新时间:2024年02月25日 14:29:02   作者:寒山李白  
在基于spring boot搭建spring cloud时,创建eureka后启动服务发生报错,本文给大家介绍了解决springboot与springcloud版本兼容问题的几种方案,需要的朋友可以参考下

1. 场景描述(产生环境)

在基于spring boot搭建spring cloud时,创建eureka后启动服务发生报错,报错内容如下,如觉得繁琐可直接看第三步解决方法进行尝试,或可直接解决问题。

注: 使用zuul的场景有些特殊,所以放在最后讲,如果是zuul使用的报错请移步5

2. 报错代码(控制台)

2.1 报错1

Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Bean

试了几次,有时候还会出现下面的报错-报错2

2.2 报错2

Could not find artifact org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:pom:2021.0.5 in alimaven (http://maven.aliyun.com/nexus/content/groups/public/)

两个版本都能对应上之后启动项目又出现了新的报错-报错3

2.3 报错3

org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:jar:unknown was not found in http://maven.aliyun.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of alimaven has elapsed or updates are forced

如果报错3的问题也解决了,这个时候使用的两个不兼容的版本,如果刷新依赖也没报错的话,启动项目后正常会报下面的错,如报错4

2.4 报错4

使用springboot2.7.3和springcloud2020.0.5后启动项目出现如下报错

Action:

Consider applying the following actions:

- Change Spring Boot version to one of the following versions [2.4.x, 2.5.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn]. 
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]

3. 解决方法

3.1 针对报错1、报错2、报错4的解决

百度后确定是版本不兼容问题,于是按照网上某博主版本列表配对,本章末尾附版本对照表可供参考。

我使用的版本是spring boot的2.7.3以及spring cloud的2021.0.5
还试了

spring boot的2.5.3以及spring cloud的2020.0.5

spring boot的2.1.4.RELEASE以及spring cloud的Greenwich.RELEASE

这三个版本都是亲测可用的(顺利起了服务并访问成功)

3.2 针对报错3的解决

版本确定没配错,那么这个报错3如果发生了,可以按照如下解决
在依赖中添加type和scope标签,如下

在父类pom.xml中配置如下

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
    </parent>

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

虽然不知道原理,但的确解决了报错3这个问题

4. 总结

正常版本兼容问题常常发生,所以一般使用偏老一点的依赖来用会减少一些问题,但很多情况下即使使用老的版本也会出现问题。

只要按照下面的方式来配置一般不会有毛病。

父项目pom.xml中的配置添加如下:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
    </parent>

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

子模块项目的pom.xml配置如下:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

5. zuul使用的报错与解决

使用兼容列表里对应的spring boot和spring cloud版本后,springcloud中的eureka等其他功能正常,但使用zuul时启动zuul服务后出现了报错,此时可尝试使用以下两个版本:spring boot 的2.2.4.RELEASE和spring cloud 的Hoxton.SR12一般可解决问题

我遇到的是如下报错:

org.springframework.cloud:spring-cloud-starter-netflix-zuul:jar:unknown was not found in http://maven.aliyun.com/nexus/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of alimaven has elapsed or updates are forced

以上两个报错都可将springboot和spring cloud的版本换为上面推荐的2.2.4.RELEASE和Hoxton.SR12即可解决问题

6. spring boot和spring cloud版本兼容表

SpringCloud版本SpringBoot版本
2022.0.0-M2Spring Boot >=3.0.0-M2 and < 3.1.0-M1
2022.0.0-M1Spring Boot >=3.0.0-M1 and < 3.0.0-M2
2021.0.3Spring Boot >=2.6.1 and < 3.0.0-M1
2021.0.0-RC1Spring Boot >=2.6.0-RC1 and <2.6.1
2021.0.0-M3Spring Boot >=2.6.0-M3 and <2.6.0-RC1
2021.0.0-M1Spring Boot >=2.6.0-M1 and <2.6.0-M3
2020.0.5Spring Boot >=2.4.0.M1 and <2.6.0-M1
Hoxton.SR12Spring Boot >=2.2.0.RELEASE and <2.4.0.M1
Hoxton.BUILD-SNAPSHOTSpring Boot >=2.2.0.BUILD-SNAPSHOT
Hoxton.M2Spring Boot >=2.2.0.M4 and <=2.2.0.M5
Greenwich.BUILD-SNAPSHOSpring Boot >=2.1.9.BUILD-SNAPSHOT and <2.2.0.M4
Greenwich.SR2Spring Boot >=2.1.0.RELEASE and <2.1.9.BUILD-SNAPSHOT
Greenwich.M1Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE
Finchley.BUILD-SNAPSHOTSpring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3
Finchley.SR4Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT
Finchley.RC2Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE
Finchley.RC1Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE
Finchley.M9Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE
Finchley.M7Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2
Finchley.M6Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1
Finchley.M5Spring Boot >=2.0.0.M7 and <=2.0.0.M7
Finchley.M4Spring Boot >=2.0.0.M6 and <=2.0.0.M6
Finchley.M3Spring Boot >=2.0.0.M5 and <=2.0.0.M5
Finchley.M2Spring Boot >=2.0.0.M3 and <2.0.0.M5
Edgware.SR51.5.20.RELEASE
Edgware.SR51.5.16.RELEASE
Edgware.RELEASE1.5.9.RELEASE
Dalston.RC11.5.2.RELEASE

以上就是解决springboot与springcloud版本兼容问题(附版本兼容表)的详细内容,更多关于springboot与springcloud版本兼容的资料请关注脚本之家其它相关文章!

相关文章

  • gRPC实践之proto及Maven插件概念及使用详解

    gRPC实践之proto及Maven插件概念及使用详解

    这篇文章主要为大家介绍了gRPC实践之proto及Maven插件概念及使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-04-04
  • Java运算符从见过到掌握下

    Java运算符从见过到掌握下

    计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量,本篇对大家的学习或工作具有一定的价值,紧接上篇,需要的朋友可以参考下
    2021-09-09
  • Java压缩文件为ZIP并加密的详细步骤

    Java压缩文件为ZIP并加密的详细步骤

    Zip是一种常用的文件压缩格式,下面这篇文章主要给大家介绍了关于Java压缩文件为ZIP并加密的详细步骤,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2023-11-11
  • SpringBoot环境Druid数据源使用及特点

    SpringBoot环境Druid数据源使用及特点

    Druid 是目前比较流行的高性能的,分布式列存储的OLAP框架(具体来说是MOLAP)。本文给大家分享SpringBoot环境Druid数据源使用及特点介绍,感兴趣的朋友跟随小编一起看看吧
    2021-07-07
  • mybaits-spring的实现方式

    mybaits-spring的实现方式

    这篇文章主要介绍了mybaits-spring的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-05-05
  • java.util.Date和java.time.LocalDate对比及分析

    java.util.Date和java.time.LocalDate对比及分析

    本文介绍了java.util.Date和java.time下的日期两种日期类型的区别和使用场景,前者表示一个瞬时时间点,包含日期+时间,后者仅表示纯日期,后者时区无关联,而前者依赖操作系统时区显示,两者之间可以相互转换,并且可以格式化输出
    2026-05-05
  • += 和 ++ 操作符区别简单介绍

    += 和 ++ 操作符区别简单介绍

    这篇文章主要介绍了+= 和 ++ 操作符区别简单介绍的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2016-09-09
  • 使用SpringBoot+AOP实现可插拔式日志的示例代码

    使用SpringBoot+AOP实现可插拔式日志的示例代码

    这篇文章主要介绍了使用SpringBoot+AOP实现可插拔式日志的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-07-07
  • java使用CollectionUtils工具类判断集合是否为空方式

    java使用CollectionUtils工具类判断集合是否为空方式

    这篇文章主要介绍了java使用CollectionUtils工具类判断集合是否为空方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-02-02
  • 详解Spring Boot微服务如何集成fescar解决分布式事务问题

    详解Spring Boot微服务如何集成fescar解决分布式事务问题

    这篇文章主要介绍了详解Spring Boot微服务如何集成fescar解决分布式事务问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-01-01

最新评论