先行一步
VMware 提供培訓和認證,加速你的發展。
瞭解更多Spring Cloud 提供工具,供開發者快速構建分散式系統中常見的一些模式(例如配置管理、服務發現、斷路器、智慧路由、微代理、控制匯流排、短命微服務和契約測試)。分散式系統的協調會產生樣板模式,而使用 Spring Cloud,開發者可以快速搭建實現這些模式的服務和應用程式。它們在任何分散式環境中都能很好地工作,包括開發者的筆記型電腦、裸金屬資料中心以及 Cloud Foundry 等託管平臺。
Spring Cloud 專注於為典型用例提供良好的開箱即用體驗,並提供擴充套件機制以覆蓋其他情況。
分散式/版本化配置
服務註冊與發現
路由
服務間呼叫
負載均衡
斷路器
分散式訊息
短命微服務(任務)
消費者驅動和生產者驅動的契約測試
最簡單的入門方式是訪問 start.spring.io,選擇你的 Spring Boot 版本和你想要使用的 Spring Cloud 專案。當你生成專案時,這會將相應的 Spring Cloud BOM 版本新增到你的 Maven/Gradle 檔案中。
如果你想將 Spring Cloud 新增到現有的 Spring Boot 應用中,第一步是確定應該使用哪個版本的 Spring Cloud。你在應用中使用的版本取決於你正在使用的 Spring Boot 版本。
下表概述了 Spring Cloud 的哪個版本對應 Spring Boot 的哪個版本。
表 1. 釋出火車與 Spring Boot 相容性(有關更詳細的資訊,請參閱 此處)。
釋出火車 | Spring Boot 版本 |
---|---|
2025.0.x 又稱 Northfields | 3.5.x |
2024.0.x 又稱 Moorgate | 3.4.x |
2023.0.x 又稱 Leyton | 3.3.x, 3.2.x |
2022.0.x 又稱 Kilburn | 3.0.x, 3.1.x (從 2022.0.3 開始) |
2021.0.x 又稱 Jubilee | 2.6.x, 2.7.x (從 2021.0.3 開始) |
2020.0.x 又稱 Ilford | 2.4.x, 2.5.x (從 2020.0.3 開始) |
Hoxton | 2.2.x, 2.3.x (從 SR5 開始) |
Greenwich | 2.1.x |
Finchley | 2.0.x |
Edgware | 1.5.x |
Dalston | 1.5.x |
Spring Cloud Dalston, Edgware, Finchley, Greenwich, 2020.0 (又稱 Ilford), 2021.0 (又稱 Jubilee), 和 2022.0 (又稱 Kilburn) 都已達到生命週期結束狀態,不再受支援。
錯誤修復和向後相容的功能透過服務版本(SR)新增到每個釋出火車中。一旦確定了要使用的 Spring Cloud 版本,就應該使用該釋出火車的最新服務版本。你可以在我們的釋出說明頁面上找到最新的服務版本資訊。
既然你知道要使用哪個釋出火車以及該釋出火車的最新服務版本,你就可以將 Spring Cloud BOM 新增到你的應用程式中了。
<properties>
<spring-cloud.version>2024.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>
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.0'
id 'io.spring.dependency-management' version '1.1.6'
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2024.0.0")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
建議你使用釋出火車 BOM
spring-cloud-dependencies
。這是一個僅包含 BOM 的版本,它只包含依賴管理,不包含外掛宣告或直接引用 Spring 或 Spring Boot。你可以使用 Spring Boot 父 POM,或使用 Spring Boot 的 BOM (spring-boot-dependencies
) 來管理 Spring Boot 版本。
就像 Spring Boot 一樣,許多 Spring Cloud 專案包含啟動器,你可以將它們作為依賴新增到你的專案中,以新增各種雲原生功能。在許多情況下,只需將啟動器新增到類路徑即可啟用許多功能。啟動器的名稱在各個專案中都有文件說明。下面是一個示例,說明如何將 Spring Cloud Config Client 和 Spring Cloud Netflix Eureka client 新增到你的應用程式中。
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
...
</dependencies>
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
//...
}
由 git 倉庫支援的集中式外部配置管理。配置資源直接對映到 Spring 的 Environment
,但如果需要,非 Spring 應用也可以使用。
Spring Cloud Gateway 是一個基於 Spring Framework 和 Spring Boot 的智慧可程式設計路由器。
與 Netflix OSS 的 Eureka 服務發現整合。
使用 Hashicorp Consul 進行服務發現和配置管理。
一個用於在現代執行時上編排可組合微服務應用程式的雲原生服務。易於使用的 DSL、拖放 GUI 和 REST-APIs 共同簡化了基於微服務的資料管道的整體編排。
Spring Cloud Function 提倡透過函式實現業務邏輯。它支援跨無伺服器提供商的統一程式設計模型,以及獨立執行(本地或 PaaS)的能力。
一個輕量級的事件驅動微服務框架,用於快速構建可以連線到外部系統的應用程式。使用簡單的宣告性模型透過 Apache Kafka 或 RabbitMQ 在 Spring Boot 應用程式之間傳送和接收訊息。
Spring Cloud Stream Applications 是開箱即用的 Spring Boot 應用程式,它們使用 Spring Cloud Stream 中的 Binder 抽象與 Apache Kafka、RabbitMQ 等外部中介軟體系統整合。
一個短命微服務框架,用於快速構建執行有限資料處理量的應用程式。為 Spring Boot 應用程式新增功能性和非功能性特性提供了簡單的宣告性方式。
Spring Cloud Task App Starters 是 Spring Boot 應用程式,它們可以是任何程序,包括 Spring Batch 作業,這些作業不會永遠執行,而是在有限的資料處理期後結束/停止。
使用 Apache Zookeeper 進行服務發現和配置管理。
Spring Cloud Contract 是一個傘形專案,包含幫助使用者成功實現消費者驅動契約方法的解決方案。
Spring Cloud OpenFeign 透過自動配置和繫結到 Spring Environment 及其他 Spring 程式設計模型慣用法,為 Spring Boot 應用程式提供整合。
一個事件匯流排,用於透過分散式訊息連線服務和服務例項。對於跨叢集傳播狀態變化(例如配置變更事件)非常有用。
為構建實現 Open Service Broker API 的服務代理提供起點。
Spring Cloud 是一個傘形專案,包含獨立的專案,這些專案原則上具有不同的釋出週期。為了管理這個組合,會發佈一個 BOM (Bill of Materials),其中包含了對各個專案精心策劃的依賴關係。轉到此處閱讀關於釋出火車命名規範的資訊。