这可能不是最好的问题,但我注意到有 2 个 Spring JPA 用于 Spring boot。它们有何不同?目前,我正在尝试与 Hibernate 一起设置 Spring Boot 1.5.3 项目。我记得我之前用 spring-boot-starter-data-jpa 用 JPA 设置了 Spring Boot。
我看到的大多数在线示例以及 starter.spring.io 都为 Spring JPA 提供了以下依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
但在一个现有项目中,我遇到了 spring-data-jpa:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.4.RELEASE</version>
</dependency>
做一点谷歌并没有告诉我它们是否不同。
在我之前添加 JPA 的所有项目中,虽然是 JPA 2.1/Hibernate,这就是为什么我有点不确定在我的新 Spring Boot 应用程序中使用这两者中的哪一个。
最佳答案
如 docs 中所述, starter
是一个方便的内联器,用于这个特定库的所有必需依赖项,即本身包含其他依赖项,而不是您手动编写这些依赖项。
查看 spring-boot-starter-data-jpa
pom.xml ,你会看到它包含 spring-data-jpa
作为许多其他依赖项。
Spring Boot Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need without having to hunt through sample code and copy paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access just include the spring-boot-starter-data-jpa dependency in your project, and you are good to go.
关于java - spring-data-jpa 和 spring-boot-starter-data-jpa 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44768112/