Spring Boot、Spring Cloud與Spring Cloud Alibaba版本對應關係

北風濁酒 發佈 2024-03-31T06:38:52.977203+00:00

由於 `Spring Boot 1 和 Spring Boot 2 在 Actuator 模塊的接口和註解有很大的變更,且 spring-cloud-commons 從 1.x.x 版本升級到 2.0.0 版本也有較大的變更,因此我們採取跟 SpringBoot 版本號一致的版本:1.5.x 版本適用於 Spring Boot 1.5.x。

一、前言

在搭建SpringCloud項目環境架構的時候,j經常需要選擇SpringBoot和SpringCloud進行兼容的版本號。因此,對於選擇SpringBoot版本與springCloud版本的對應關係很重要,如果版本關係不對應,常見的會遇見項目啟動不起來,怪異的則會是你的項目出現一些詭異的問題,查資料也不好查。下面就收集一下SpringBoot與SpringCloud版本之間的對應關係,在搭建項目框架或者學習時按照對應的版本區間進行選擇即可,避免走一些不必要的彎路。

1. 歷史版本圖

Release train Spring Boot compatibility

注意: 官方通告SpringBoot1.5.x及以下版本官方不再提供維護了,建議開發者選擇使用SpringBoot2.0.x以上的版本,相對應的SpringCloud版本也最好不要使用。

二、查看版本關係

訪問Spring官方地址,可獲取SpringBoot和SpringCloud版本對應信息。

地址如下:

https://start.spring.io/actuator/info

JSON格式如下:

JSON["bom-ranges"]["spring-cloud"]["Finchley.M9"]◣
Path:
JSON["bom-ranges"]["spring-cloud"]["Finchley.M9"]
 
Key:
Finchley.M9
 : Copy deURI deBase64 aLine Copied!
 
Modify
+Expand all -Collapse all Expand node Scroll to node
 
Show value Show img Show array leng Show ico
JSON
git
commit
time2020-04-17T16:18:36Z
id7f707c1
branch7f707c17bed34a13b5bc9d5d58c71fc5a901c335
build
version0.0.1-SNAPSHOT
artifactstart-site
namestart.spring.io website
versions
initializr0.9.0.BUILD-SNAPSHOT
spring-boot2.2.6.RELEASE
groupio.spring.start
time2020-04-17T16:19:53.303Z
bom-ranges
azure
2.0.10Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE
2.1.7Spring Boot >=2.1.0.RELEASE and <2.2.0.M1
2.2.0Spring Boot >=2.2.0.M1
codecentric-spring-boot-admin
2.0.6Spring Boot >=2.0.0.M1 and <2.1.0.M1
2.1.6Spring Boot >=2.1.0.M1 and <2.2.0.M1
2.2.1Spring Boot >=2.2.0.M1
solace-spring-boot
1.0.0Spring Boot >=2.2.0.RELEASE and <2.3.0.M1
solace-spring-cloud
1.0.0Spring Boot >=2.2.0.RELEASE and <2.3.0.M1
spring-cloud
Finchley.M2Spring Boot >=2.0.0.M3 and <2.0.0.M5
Finchley.M3Spring Boot >=2.0.0.M5 and <=2.0.0.M5
Finchley.M4Spring Boot >=2.0.0.M6 and <=2.0.0.M6
Finchley.M5Spring Boot >=2.0.0.M7 and <=2.0.0.M7
Finchley.M6Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1
Finchley.M7Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2
Finchley.M9Spring Boot >=2.0.0.RELEASE and <=2.0.0.RELEASE
Finchley.RC1Spring Boot >=2.0.1.RELEASE and <2.0.2.RELEASE
Finchley.RC2Spring Boot >=2.0.2.RELEASE and <2.0.3.RELEASE
Finchley.SR4Spring Boot >=2.0.3.RELEASE and <2.0.999.BUILD-SNAPSHOT
Finchley.BUILD-SNAPSHOTSpring Boot >=2.0.999.BUILD-SNAPSHOT and <2.1.0.M3
Greenwich.M1Spring Boot >=2.1.0.M3 and <2.1.0.RELEASE
Greenwich.SR5Spring Boot >=2.1.0.RELEASE and <2.1.14.BUILD-SNAPSHOT
Greenwich.BUILD-SNAPSHOTSpring Boot >=2.1.14.BUILD-SNAPSHOT and <2.2.0.M4
Hoxton.SR3Spring Boot >=2.2.0.M4 and <2.3.0.BUILD-SNAPSHOT
Hoxton.BUILD-SNAPSHOTSpring Boot >=2.3.0.BUILD-SNAPSHOT
spring-cloud-alibaba
2.2.0.RELEASESpring Boot >=2.2.0.RELEASE and <2.3.0.M1
spring-cloud-services
2.0.3.RELEASESpring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE
2.1.7.RELEASESpring Boot >=2.1.0.RELEASE and <2.2.0.RELEASE
2.2.3.RELEASESpring Boot >=2.2.0.RELEASE and <2.3.0.M1
spring-statemachine
2.0.0.M4Spring Boot >=2.0.0.RC1 and <=2.0.0.RC1
2.0.0.M5Spring Boot >=2.0.0.RC2 and <=2.0.0.RC2
2.0.1.RELEASESpring Boot >=2.0.0.RELEASE
vaadin
10.0.17Spring Boot >=2.0.0.M1 and <2.1.0.M1
14.1.25Spring Boot >=2.1.0.M1
dependency-ranges
okta
1.2.1Spring Boot >=2.1.2.RELEASE and <2.2.0.M1
1.4.0Spring Boot >=2.2.0.M1
mybatis
2.0.1Spring Boot >=2.0.0.RELEASE and <2.1.0.RELEASE
2.1.2Spring Boot >=2.1.0.RELEASE
geode
1.2.6.RELEASESpring Boot >=2.2.0.M5 and <2.3.0.M1
1.3.0.M3Spring Boot >=2.3.0.M1 and <2.3.0.BUILD-SNAPSHOT
1.3.0.BUILD-SNAPSHOTSpring Boot >=2.3.0.BUILD-SNAPSHOT
camel
2.22.4Spring Boot >=2.0.0.M1 and <2.1.0.M1
2.25.1Spring Boot >=2.1.0.M1 and <2.2.0.M1
3.2.0Spring Boot >=2.2.0.M1

三、如何選擇SpringBoot與SpringCloud版本號

項目搭建初期,如何對SpringBoot和SpringCloud的一個相互兼容性版本號進行選擇,這是很重要的一步,例如SpringCloud的Hoxton.SR3這個版本,他對應的"Spring Boot >=2.2.0.M4 and <2.3.0.BUILD-SNAPSHOT"版本,意思就是如果選擇使用SpringCloud 的Hoxton.SR3這個版本,那麼SpringBoot的版本需要大於等於2.2.0小於2.3.0即可滿足兼容性。

1. 引入SpringCloud版本管理

官方提供了管理Spring Cloud 每個版本兼容的pom,引入下面依賴管理信息即可:

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

2. 使用Spring Boot

Spring Boot可以也像父工程那樣管理自己內部的兼容版本號,如下:

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.2.5.RELEASE</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>

四、SpringBoot、SpringCloud、SpringCloudAlibaba版本對應關係

由於Spring Cloud基於Spring Boot構建,而Spring Cloud Alibaba又基於Spring Cloud Common的規範實現,所以當我們使用``Spring Cloud Alibaba`來構建微服務應用的時候,需要知道這三者之間的版本關係。

下表整理了目前Spring Cloud Alibaba的版本與Spring Boot、Spring Cloud版本的兼容關係:

1. 畢業版本依賴關係(推薦使用)

五. Spring Cloud Alibaba與組件版本關係

Spring Cloud Alibaba是基於Spring Cloud Common的規範實現,而Spring Cloud Alibaba的各個微服務組件依賴於Spring Cloud Alibaba自身,因此我們需要知道Spring Cloud Alibaba與其自身微服務組件之間的版本關係。

下表整理了目前Spring Cloud Alibaba的版本與Sentinel、Nacos 、RocketMQ 、Dubbo、Seata版本的兼容關係:

1. 組件版本關係

六、依賴管理

Spring Cloud Alibaba BOM 包含了它所使用的所有依賴的版本。

1. RELEASE 版本

Spring Cloud Hoxton

如果需要使用 Spring Cloud Hoxton 版本,請在 dependencyManagement中添加如下配置

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.2.3.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

然後在dependencies 中添加自己所需使用的依賴即可使用。

Spring Cloud Greenwich

如果需要使用 Spring Cloud Greenwich版本,請在 dependencyManagement中添加如下配置

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.1.3.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

然後在 dependencies中添加自己所需使用的依賴即可使用。

Spring Cloud Finchley

如果需要使用 Spring Cloud Finchley版本,請在 dependencyManagement中添加如下配置

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>2.0.3.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

然後在dependencies中添加自己所需使用的依賴即可使用。

Spring Cloud Edgware

如果需要使用 Spring Cloud Edgware 版本,請在 dependencyManagement中添加如下配置

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-alibaba-dependencies</artifactId>
    <version>1.5.1.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

然後在 dependencies中添加自己所需使用的依賴即可使用。

2. 版本管理規範

項目的版本號格式為 x.x.x 的形式,其中 x 的數值類型為數字,從 0 開始取值,且不限於 0~9 這個範圍。項目處於孵化器階段時,第一位版本號固定使用 0,即版本號為 0.x.x 的格式。

由於 `Spring Boot 1 和 Spring Boot 2 在 Actuator 模塊的接口和註解有很大的變更,且 spring-cloud-commons 從 1.x.x 版本升級到 2.0.0 版本也有較大的變更,因此我們採取跟 SpringBoot 版本號一致的版本:

  • 1.5.x 版本適用於 Spring Boot 1.5.x
  • 2.0.x 版本適用於 Spring Boot 2.0.x
  • 2.1.x 版本適用於 Spring Boot 2.1.x
  • 2.2.x 版本適用於 Spring Boot 2.2.x

七、參考文檔

1.Spring-Cloud-Alibaba版本說明:https://github.com/alibaba/spring-cloud-alibaba/wiki/版本說明

3.SpringCloudAlibaba中文社區地址: https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md

2.SpringCloud官方文檔:https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/

關鍵字: