相依性

由於個別 Spring Data 模組的初始發布日期不同,它們大多帶有不同的主要和次要版本號。 尋找相容版本的最簡單方法是依賴我們隨附定義相容版本的 Spring Data Release Train BOM。 在 Maven 專案中,您會在 POM 的 <dependencyManagement /> 區段中宣告此相依性,如下所示

使用 Spring Data 發行列車 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>

目前的發行列車版本為 2024.1.0。 列車版本使用 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 屬性設定為您想要使用的列車版本和迭代

請參閱 Spring Boot 的文件 (搜尋 "Spring Data Bom") 以取得更多詳細資訊。

Spring Framework

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