Spring Boot 如何提供 spring-data-jpa v1.10.3.RELEASE



>我有一个带有POM的项目,它指定了对spring-data-jpa的依赖关系,如下所示:

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>

它没有版本号,但是当我运行mvn:dependency:tree时,我可以看到如下所示的相关部分......

|  - org.springframework:spring-orm:jar:4.3.3.RELEASE:compile
[INFO] +- **org.springframework.data:spring-data-jpa:jar:1.10.3.RELEASE**:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.12.3.RELEASE:compile
[INFO] |  - org.aspectj:aspectjrt:jar:1.8.9:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.0.11.Final:compile

。它显示它与版本1.10.3.RELEASE。

我想知道它最终是如何附带版本号的。我抬头看了看,它既不是最新的Maven存储库的Spring Data JPA版本号,也不是其父POM中定义该依赖项的部分。POM项目如下所示:

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${springboot-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${springboot-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springboot-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>${springboot-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>

spring-data-jpa的版本由 spring-boot-parent 提供。

您可以在 Spring Boot 文档的附录依赖项版本部分查看 Spring 引导版本和spring-data-jpa之间的关系。

例如,最新版本的 Spring Boot 将提供spring-data-jpa的版本1.11.9.RELEASE

在您的问题中,您显示:org.springframework.data:spring-data-jpa:jar:1.10.3.RELEASE这表明您使用的是 Spring Boot 的 v1.4.x,则相关的依赖项显示在 Spring Boot 的 v1.4.1 文档中:

org.springframework.data spring-data-jpa1.10.3.RELEASE

spring-boot1.4.1.RELEASE 和spring-data-jpa1.10.3.RELEASE 之间的关系由 Maven 促进,因为 Maven 遵循 Spring Boot 的 POM 中定义的关系。

来自文档(我的强调):

Spring Boot 的每个版本都提供了它支持的依赖项的精选列表。实际上,您不需要在构建配置中为任何这些依赖项提供版本,因为 Spring Boot 会为您管理它

精选列表包含可用于 Spring Boot 的所有 Spring 模块,以及第三方库的优化列表。该列表可作为标准物料清单(spring-boot-dependencies)提供,可用于Maven和Gradle。

因此,Spring Boot 为您提供了spring-boot-starter-data-jpa,进而通过对spring-data-releasetrain的依赖提供spring-data-jpa。其确切机制是:

  1. spring-boot-starter-data-jpa声明了对spring-data-jpa的依赖。
  2. spring-boot-starter-data-jpaspring-boot-starters养育
  3. spring-boot-startersspring-boot-parent养育
  4. spring-boot-parentspring-boot-dependencies养育
  5. spring-boot-dependencies导入spring-data-releasetrainPOM:

    <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-releasetrain</artifactId>
    <version>${spring-data-releasetrain.version}</version>
    <scope>import</scope>
    <type>pom</type>
    </dependency>
    

最新更新