Java spring-data-jpa 和 spring-boot-starter-data-jpa 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44768112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between spring-data-jpa and spring-boot-starter-data-jpa
提问by Acewin
This may not be the best question to ask, but I noticed there are 2 Spring JPA for Spring boot. How are they different. Currently I am trying to setup SpringBoot 1.5.3 project along with hibernate. I remember I had setup Springboot with JPA earlier with spring-boot-starter-data-jpa.
这可能不是最好的问题,但我注意到 Spring boot 有 2 个 Spring JPA。他们有什么不同。目前我正在尝试将 SpringBoot 1.5.3 项目与休眠一起设置。我记得我之前用 spring-boot-starter-data-jpa 设置了带有 JPA 的 Springboot。
Most of the online examples I have seen as well as starter.spring.io provides below dependency for spring jpa.
我见过的大多数在线示例以及 starter.spring.io 为 spring jpa 提供了以下依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
But in one of the existing project I came across spring-data-jpa
但是在现有项目之一中,我遇到了 spring-data-jpa
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.4.RELEASE</version>
</dependency>
Doing a bit of google did not give me if they are different or not.
如果它们不同,做一点谷歌并没有给我。
In all my previous projects where I added JPA was though JPA 2.1/Hibernate that is why I am a bit unsure which of the 2 to use in my new SpringBoot application.
在我之前添加 JPA 的所有项目中,虽然 JPA 2.1/Hibernate 这就是为什么我有点不确定在我的新 SpringBoot 应用程序中使用这两个中的哪一个。
采纳答案by Artem Novikov
As stated in the docs, the starter
one is a convenient inliner for all required dependencies for this particular library, i.e. includes other dependencies in itself, instead of you writing those manually.
正如文档中所述,starter
一个是此特定库的所有必需依赖项的方便内联程序,即在其自身中包含其他依赖项,而不是您手动编写这些依赖项。
Look into the spring-boot-starter-data-jpa
pom.xml, you will see there it includes spring-data-jpa
as a dependency among many others.
查看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.
Spring Boot Starters 是一组方便的依赖描述符,您可以将其包含在您的应用程序中。您可以获得所需的所有 Spring 和相关技术的一站式服务,而无需搜索示例代码和复制粘贴加载的依赖项描述符。例如,如果您想开始使用 Spring 和 JPA 进行数据库访问,只需在您的项目中包含 spring-boot-starter-data-jpa 依赖项,就可以了。
回答by Sanora
Check the pom.xml for spring-boot-starter-data-jpa here: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-starters/spring-boot-starter-data-jpa/pom.xml
在此处检查 spring-boot-starter-data-jpa 的 pom.xml:https: //github.com/spring-projects/spring-boot/blob/master/spring-boot-starters/spring-boot-starter-data -jpa/pom.xml
Read the description tag which says: "Starter for using Spring Data JPA with Hibernate".
阅读描述标签,上面写着:“Starter for using Spring Data JPA with Hibernate”。
So spring-boot-starter-data-jpa uses Spring Data JPA with Hibernate as the implementation. This is hard-coded, so to speak.
所以 spring-boot-starter-data-jpa 使用 Spring Data JPA 和 Hibernate 作为实现。可以这么说,这是硬编码的。
If you now check the pom.xml for spring-data-jpa, it is implementation-agnostic. And to use Spring Data JPA in any project, one mustprovide the implementation to use. Not doing that will give you an error.
如果您现在检查 spring-data-jpa 的 pom.xml,则它与实现无关。并且要在任何项目中使用 Spring Data JPA,必须提供要使用的实现。不这样做会给你一个错误。
Spring Data JPA documentation states that it currently supports Hibernate 5, (Apache) OpenJPA 2.4 and EclipseLink 2.6.1. Read here: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#new-features.1-10-0
Spring Data JPA 文档指出它目前支持 Hibernate 5、(Apache) OpenJPA 2.4 和 EclipseLink 2.6.1。在这里阅读:https: //docs.spring.io/spring-data/jpa/docs/current/reference/html/#new-features.1-10-0