简体   繁体   English

spring-data-jpa和spring-boot-starter-data-jpa之间的区别

[英]Difference between spring-data-jpa and spring-boot-starter-data-jpa

This may not be the best question to ask, but I noticed there are 2 Spring JPA for Spring boot. 这可能不是最好的问题,但我注意到Spring引导有2个Spring JPA。 How are they different. 他们有什么不同。 Currently I am trying to setup SpringBoot 1.5.3 project along with hibernate. 目前我正在尝试与hibernate一起设置SpringBoot 1.5.3项目。 I remember I had setup Springboot with JPA earlier with spring-boot-starter-data-jpa. 我记得我之前使用spring-boot-starter-data-jpa设置了Springboot和JPA。

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应用程序中使用哪两个。

As stated in the docs , the starter one is a convenient inliner for all required dependencies for this particular library, ie includes other dependencies in itself, instead of you writing those manually. 正如文档中所述,对于这个特定的库, starter是一个方便的内联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. Spring Boot Starters是一组方便的依赖描述符,您可以在应用程序中包含这些描述符。 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. 您可以获得所需的所有Spring和相关技术的一站式服务,而无需搜索示例代码并复制粘贴的依赖描述符。 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和JPA进行数据库访问,只需在项目中包含spring-boot-starter-data-jpa依赖项,您就可以了。

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 在这里查看pom.xml中的spring-boot-starter-data-jpa: 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". 阅读描述标签,其中写着:“使用Spring Data JPA和Hibernate的初学者”。

So spring-boot-starter-data-jpa uses Spring Data JPA with Hibernate as the implementation. 所以spring-boot-starter-data-jpa使用Spring Data JPA和Hibernate作为实现。 This is hard-coded, so to speak. 可以这么说,这是硬编码的。

If you now check the pom.xml for spring-data-jpa, it is implementation-agnostic. 如果现在检查pom.xml中的spring-data-jpa,它与实现无关。 And to use Spring Data JPA in any project, one must provide the implementation to use. 要在任何项目中使用Spring Data JPA, 必须提供要使用的实现。 Not doing that will give you an error. 不这样做会给你一个错误。

Spring Data JPA documentation states that it currently supports Hibernate 5, (Apache) OpenJPA 2.4 and EclipseLink 2.6.1. Spring Data JPA文档指出它目前支持Hibernate 5,(Apache)OpenJPA 2.4和EclipseLink 2.6.1。 Read here: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#new-features.1-10-0 在这里阅读: https//docs.spring.io/spring-data/jpa/docs/current/reference/html/#new-features.1-10-0

Spring Boot provides spring-boot-starter-data-jpa starter to connect spring application with relational database efficiently. Spring Boot提供了spring-boot-starter-data-jpa启动程序,可以有效地将spring应用程序与关系数据库连接起来。 The starter have additional dependencies. 启动器具有其他依赖项。

spring-data-jpa is used as a dependency for spring-boot-starter-data-jpa . spring-data-jpa用作spring-boot-starter-data-jpa的依赖项。 Since you use spring boot version 1.5.3, you may have a look at here . 由于您使用的是Spring Boot 1.5.3版本,因此您可以查看此处

spring-data-jpa , part of the larger Spring Data family, makes it easy to easily implement JPA based repositories. spring-data-jpa是更大的Spring Data系列的一部分,可以轻松实现基于JPA的存储库。 This module deals with enhanced support for JPA based data access layers. 此模块处理对基于JPA的数据访问层的增强支持。 It makes it easier to build Spring-powered applications that use data access technologies. 它使构建使用数据访问技术的Spring驱动应用程序变得更加容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导不添加 spring-boot-starter-data-jpa - Spring boot not adding spring-boot-starter-data-jpa Java:依赖项目中的spring-boot-starter-data-jpa依赖 - Java : spring-boot-starter-data-jpa dependency in a dependent project spring-boot-starter-data-jpa依赖错误 - spring-boot-starter-data-jpa dependency error 有关Spring-boot-starter-data-jpa的问题 - A question about the Spring-boot-starter-data-jpa spring-boot-starter-data-jpa:自动重新连接 - spring-boot-starter-data-jpa : Auto Reconnect H2 数据库是用 spring-boot-starter-data-jpa 创建的,但不是用 spring-boot-starter-data-jdbc 创建的 - H2 Database created with spring-boot-starter-data-jpa but not with spring-boot-starter-data-jdbc 在单元测试中带有spring-boot-starter-data-jpa的Spring Boot需要强制使用@DataJpaTest - Spring Boot with spring-boot-starter-data-jpa in unit test needs mandatory @DataJpaTest 将“spring-boot-starter-data-jpa”依赖项添加到Spring项目时出错 - Error when adding “spring-boot-starter-data-jpa” dependency to Spring project 排除 JPA Spring boot - org.springframework.boot:spring-boot-starter-data-jpa&#39; 启动时导致 CRUDRepository 错误 - Exclude JPA Spring boot - org.springframework.boot:spring-boot-starter-data-jpa' causes error in CRUDRepository when starting 未找到依赖项 &#39;org.springframework.boot:spring-boot-starter-data-jpa:2.5.3&#39; - Dependency 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.3' not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM