依賴

由於各個 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。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")。

Spring Framework

當前版本的 Spring Data 模組需要 Spring Framework 6.2.6 或更高版本。這些模組也可能與該次要版本的較舊 bugfix 版本相容。但是,強烈建議使用該代中最新的版本。