版本与兼容性 #
一、版本命名规则 #
1.1 旧版命名规则(2020年前) #
Spring Cloud早期版本使用伦敦地铁站名称作为版本代号,按字母顺序排列:
| 版本代号 | 发布时间 | 说明 |
|---|---|---|
| Angel | 2015年 | 第一个正式版本 |
| Brixton | 2016年 | 添加更多Netflix组件 |
| Camden | 2016年 | 完善生态系统 |
| Dalston | 2017年 | 稳定性提升 |
| Edgware | 2017年 | 功能增强 |
| Finchley | 2018年 | 支持Spring Boot 2.0 |
| Greenwich | 2019年 | 支持JDK 11 |
| Hoxton | 2019年 | 支持JDK 13 |
1.2 新版命名规则(2020年后) #
从2020年开始,Spring Cloud采用日历化版本命名:
text
年份.次要版本.补丁版本
示例:2021.0.0
- 2021:2021年发布
- 0:次要版本
- 0:补丁版本
| 版本 | 发布时间 | Spring Boot版本 |
|---|---|---|
| 2020.0.x | 2020年 | 2.4.x / 2.5.x |
| 2021.0.x | 2021年 | 2.6.x / 2.7.x |
| 2022.0.x | 2022年 | 3.0.x |
| 2023.0.x | 2023年 | 3.1.x / 3.2.x |
1.3 版本后缀说明 #
| 后缀 | 说明 |
|---|---|
| SNAPSHOT | 快照版,开发中版本 |
| M1, M2… | 里程碑版本 |
| RC1, RC2… | 发布候选版本 |
| RELEASE | 正式发布版本 |
| SR1, SR2… | 服务发布版本(补丁) |
二、兼容性矩阵 #
2.1 Spring Cloud与Spring Boot兼容性 #
重要:Spring Cloud与Spring Boot版本必须严格对应!
| Spring Cloud版本 | Spring Boot版本 | JDK版本 |
|---|---|---|
| 2023.0.x (Leyton) | 3.2.x, 3.3.x | 17 - 21 |
| 2022.0.x (Kilburn) | 3.0.x, 3.1.x | 17 - 21 |
| 2021.0.x (Jubilee) | 2.6.x, 2.7.x | 8 - 17 |
| 2020.0.x (Ilford) | 2.4.x, 2.5.x | 8 - 17 |
| Hoxton | 2.2.x, 2.3.x | 8 - 11 |
| Greenwich | 2.1.x | 8 - 11 |
| Finchley | 2.0.x | 8 |
2.2 Spring Cloud Alibaba兼容性 #
| Spring Cloud Alibaba | Spring Cloud | Spring Boot |
|---|---|---|
| 2022.0.0.0 | 2022.0.x | 3.0.x |
| 2021.0.5.0 | 2021.0.x | 2.6.x, 2.7.x |
| 2021.0.4.0 | 2021.0.x | 2.6.x |
| 2020.0 | 2020.0.x | 2.4.x, 2.5.x |
| 2.2.x | Hoxton | 2.2.x, 2.3.x |
| 2.1.x | Greenwich | 2.1.x |
2.3 完整兼容性查询 #
访问官方页面查询最新兼容性:
三、版本选择建议 #
3.1 新项目推荐 #
| 场景 | 推荐版本 | 说明 |
|---|---|---|
| 全新项目 | Spring Cloud 2023.0.x + Spring Boot 3.2.x | 最新稳定版 |
| 企业稳定项目 | Spring Cloud 2022.0.x + Spring Boot 3.0.x | 长期支持 |
| 遗留系统 | Spring Cloud 2021.0.x + Spring Boot 2.7.x | 兼容JDK 8 |
3.2 版本选择原则 #
text
1. 稳定性优先
└── 选择RELEASE或SR版本,避免SNAPSHOT
2. 兼容性检查
└── 确保Spring Cloud、Spring Boot、JDK版本兼容
3. 组件兼容
└── 检查第三方组件是否支持所选版本
4. 长期支持
└── 优先选择LTS版本
3.3 版本升级策略 #
升级前准备:
- 阅读官方Release Notes
- 检查Breaking Changes
- 在测试环境验证
- 制定回滚方案
升级步骤:
xml
<!-- 1. 更新父POM版本 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
</parent>
<!-- 2. 更新Spring Cloud版本 -->
<properties>
<spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 3. 更新Spring Cloud Alibaba版本 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2022.0.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
四、依赖管理 #
4.1 使用BOM管理版本 #
Spring Cloud使用BOM(Bill of Materials)管理版本依赖:
xml
<dependencyManagement>
<dependencies>
<!-- Spring Cloud BOM -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2023.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Spring Cloud Alibaba BOM -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2022.0.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
4.2 添加组件依赖 #
使用BOM后,添加组件时无需指定版本:
xml
<dependencies>
<!-- Eureka客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- Nacos配置中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- Gateway网关 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
</dependencies>
4.3 Gradle配置 #
groovy
ext {
springCloudVersion = "2023.0.0"
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
}
五、常见版本问题 #
5.1 版本不兼容错误 #
错误示例:
text
java.lang.NoSuchMethodError:
org.springframework.boot.autoconfigure.web.ServerProperties.getServlet()...
原因: Spring Cloud与Spring Boot版本不匹配
解决方案: 检查版本兼容性矩阵,使用匹配的版本
5.2 组件版本冲突 #
错误示例:
text
ClassNotFoundException:
org.springframework.cloud.client.discovery.EnableDiscoveryClient
原因: 依赖版本冲突
解决方案: 使用Maven Dependency Analyzer排查
bash
mvn dependency:tree
5.3 JDK版本问题 #
错误示例:
text
class file has wrong version 61.0, should be 55.0
原因: JDK版本不匹配
解决方案:
- Spring Boot 3.x 需要 JDK 17+
- Spring Boot 2.x 支持 JDK 8+
六、版本查询工具 #
6.1 在线查询 #
| 工具 | 地址 |
|---|---|
| Spring Initializr | https://start.spring.io |
| Spring Cloud版本查询 | https://spring.io/projects/spring-cloud |
| Maven Central | https://search.maven.org |
6.2 命令行查询 #
bash
# 查看当前项目依赖版本
mvn dependency:tree
# 查看有效POM
mvn help:effective-pom
# 检查依赖更新
mvn versions:display-dependency-updates
6.3 代码中查询版本 #
java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
// 打印Spring Boot版本
System.out.println("Spring Boot: " +
SpringBootVersion.getVersion());
// 打印Spring Cloud版本
System.out.println("Spring Cloud: " +
SpringCloudVersion.class.getPackage().getImplementationVersion());
}
}
七、总结 #
7.1 核心要点 #
| 要点 | 说明 |
|---|---|
| 版本命名 | 旧版用地铁站名,新版用日历化命名 |
| 兼容性 | Spring Cloud与Spring Boot必须严格对应 |
| BOM管理 | 使用BOM统一管理版本 |
| 版本选择 | 新项目选最新稳定版,老项目注意兼容性 |
7.2 下一步 #
现在你已经了解了版本与兼容性,接下来让我们 快速开始,创建第一个Spring Cloud微服务项目!
最后更新:2026-03-28