相依性

由於個別 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.0</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

目前的 release train 版本為 2024.1.0。 train 版本使用 calver,模式為 YYYY.MINOR.MICRO。 版本名稱對於 GA 版本和服務版本遵循 ${calver},對於所有其他版本則遵循以下模式:${calver}-${modifier},其中 modifier 可以是以下其中之一

  • SNAPSHOT:目前的快照

  • M1M2 等:里程碑版本

  • RC1RC2 等:候選發布版本

您可以在我們的 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")。

Spring Framework

目前版本的 Spring Data 模組需要 Spring Framework 6.2.0 或更高版本。 這些模組也可能適用於該次要版本的較舊錯誤修正版本。 但是,強烈建議使用該世代中的最新版本。