依賴項

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

當前的發行版列車版本是 2024.1.5。列車版本使用 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 屬性設定為你希望使用的列車版本和迭代

更多詳情請參閱 Spring Boot 的文件(搜尋 "Spring Data Bom")。

Spring Framework

當前版本的 Spring Data 模組要求 Spring Framework 6.2.6 或更高版本。這些模組也可能與該次要版本的較舊錯誤修正版本一起使用。但是,強烈建議使用該代中的最新版本。