java - spring-data-jpa 和 spring-boot-starter-data-jpa 的区别

标签 java spring spring-boot spring-data spring-data-jpa

这可能不是最好的问题,但我注意到有 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/

相关文章:

java - ListView.getChildAt() 获取不在屏幕上的 child

java - 在面板的中南添加标签?

java - Spring Batch Processor 未运行 ItemProcessor Listener

java - Keycloak无法获取访问 token

spring-boot - Prometheus 端点是一个空白页 - 在 Spring Boot 应用程序中使用 kamon 和 Prometheus 报告器

java - 使用 Java 8 Streams 如何将枚举对象数组转换为另一个枚举数组

java - 以不同顺序调用接口(interface)方法

java - ServiceConfigurationError - Keycloak 配置未找到 SPI 用户存储提供程序

java - 使用 JMH 对简单的 Spring 应用程序进行基准测试

java - 已删除的实体实例在 Spring boot 单元测试中仍然存在