spring boot与spring cloud版本兼容问题解决(附版本兼容表)

🤟致敬读者

  • 🟩感谢阅读🟦笑口常开🟪生日快乐⬛早点下班

📘博主相关



📃文章前言

  • 🔷文章均为学习工作中整理的笔记。
  • 🔶如有错误请指正,共同学习进步。

以下为解决报错问题,如果看完还不能解决,可以参考下面这篇文章搭建spring cloud
spring cloud搭建

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

或者以下报错:

Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

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

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

这是参考的一位博主的表格,对于更详细的版本介绍请移步这位博主的文章: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

📜文末寄语

  • 🟠关注我,获取更多内容。
  • 🟡技术动态、实战教程、问题解决方案等内容持续更新中。
  • 🟢《全栈知识库》技社区,集结全栈各领域开发者,期待你的加入。
  • 🔵​加入开发者的《专属社群》,分享交流,技术之路不再孤独,一起变强。
  • 🟣点击下方名片获取更多内容🍭🍭🍭👇

### 回答1: Spring Boot 2.7 对应的 Spring Cloud 版本Spring Cloud 2021.0.0。这个版本Spring Cloud 包含了一些新的特性和改进,比如支持 Spring Boot 2.7、支持 Java 17、增强了 Spring Cloud Gateway 的性能等等。同时,这个版本也修复了一些已知的 bug,提高了系统的稳定性和可靠性。如果你正在使用 Spring Boot 2.7,建议使用 Spring Cloud 2021.0.0 来构建你的微服务应用。 ### 回答2: Spring Boot 是一个用于快速构建基于 Spring 框架的应用程序的框架,它简化了 Spring 应用程序的开发过程,使开发人员能够更快地将应用程序部署到生产环境中。而 Spring Cloud 是基于 Spring Boot 的开发工具,它提供了一组工具以帮助开发人员快速构建分布式系统中的常见模式。Spring Cloud 将众多流行的服务发现、配置管理和负载均衡等技术集成到一个易于使用的框架中,大大减轻了开发人员构建分布式系统的负担。 Spring Boot 2.7 是最新版本Spring Boot,它引入了许多新功能和改进,使其更适用于构建现代化的云原生应用程序。Spring Cloud Spring Boot 2.7 结合使用,可以提供一组更强大的工具,帮助开发人员更容易地构建分布式系统,其中包括: 1. Spring Cloud Kubernetes Starter – 使 Spring 应用程序更加容易地部署到 Kubernetes 等容器化平台上,并进行动态配置、服务发现和负载均衡等操作。 2. Spring Cloud Gateway – 提供了一组强大的 API 网关功能,包括请求路由、负载均衡、熔断和降级等操作,使开发人员能够更轻松地将应用程序暴露给外部世界。 3. Spring Cloud Stream – 提供了一组易于使用的消息传递工具,使开发人员能够更容易地在分布式系统中传输消息。 4. Spring Cloud Security – 提供了一组安全工具,使开发人员能够更好地保护应用程序中的敏感数据和业务逻辑。 综上所述,Spring Boot 2.7 Spring Cloud 的结合使得开发人员能够更轻松地构建分布式系统,提高了应用程序的可扩展性、可靠性和安全性,是构建现代化的云原生应用程序的理想选择。 ### 回答3: Spring Boot 2.7是最新的Spring Boot版本它对应的是Spring Cloud 2023.1.0版本Spring Boot是一种快速开发应用程序的框架,可以轻松地创建独立的、生产就绪的Spring基于应用程序。它基于Spring框架,提供了各种各样的功能和特性,使得开发人员可以轻松、快速地开发应用程序。而Spring Cloud是负责开发分布式系统的框架,它为开发人员提供了构建和管理分布式系统的基础设施服务,包括配置管理、服务发现、负载平衡、熔断器、消息总线等等。 Spring Boot 2.7Spring Cloud 2023.1.0版本的配合使用,可以为开发人员提供更强大的功能和工具,减少了开发分布式系统的复杂性和工作量。此外,这两个框架的配合使用,还可以更加轻松地实现微服务架构,使得开发人员可以更加高效地构建可扩展、高性能和可维护的应用程序。 总之,Spring Boot 2.7和Spring Cloud 2023.1.0版本的配合使用,可以为开发人员提供更加优质的编程体验和更加高效的开发效率,使得分布式系统的开发变得更加轻松和简单。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值