依賴項
由於各個 Spring Data 模組的建立日期不同,它們中的大多數都帶有不同的主版本和次版本號。找到相容版本最簡單的方法是依賴我們提供的 Spring Data Release Train BOM,其中定義了相容版本。在 Maven 專案中,你需要在 POM 的 <dependencyManagement />
部分宣告此依賴項,如下所示
使用 Spring Data release train BOM
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-bom</artifactId>
<version>2024.1.5</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
當前的 release train 版本是 2024.1.5
。release train 版本使用 calver,模式為 YYYY.MINOR.MICRO
。對於 GA 釋出和服務釋出,版本名稱遵循 ${calver}
模式;對於所有其他版本,遵循以下模式:${calver}-${modifier}
,其中 modifier
可以是以下之一
-
SNAPSHOT
:當前快照 -
M1
、M2
等:里程碑 -
RC1
、RC2
等:釋出候選版
您可以在我們的 Spring Data 示例倉庫 中找到使用 BOM 的工作示例。配置完成後,您可以在 <dependencies />
塊中宣告您希望使用的 Spring Data 模組,而無需指定版本,如下所示
宣告對 Spring Data 模組(例如 JPA)的依賴項
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependencies>
使用 Spring Boot 進行依賴項管理
Spring Boot 會為您選擇一個最新版本的 Spring Data 模組。如果您仍然希望升級到更新的版本,請將 spring-data-bom.version
屬性設定為您希望使用的 train 版本和迭代。
有關更多詳細資訊,請參閱 Spring Boot 的文件(搜尋“Spring Data Bom”)。