在没有Spring Boot应用程序的情况下使用Spring Data JPA [英] Use Spring Data JPA without Spring Boot application

查看:82
本文介绍了在没有Spring Boot应用程序的情况下使用Spring Data JPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道是否可以在没有其余Spring框架的情况下使用Spring Data JPA?我在另一个项目的Spring Boot Web应用程序中使用了Spring Data JPA,真的很喜欢它的易用性.

现在,我与一些朋友一起为一个不带服务器的桌面应用程序提供了一个小项目,我真的很想使用Spring Data JPA,但是我找不到任何地方的信息,是否可以在没有Beans或Spring框架其余部分的情况下使用它.

这可能还是我应该尝试使用其他JPA?


I wanted to know if it is possible to use the Spring Data JPA without the rest of the spring framework? I used Spring Data JPA in a Spring Boot web application for another project and really liked how easy it was to use.

Now I have a little project with some friends for a Desktop application without a server and would really like to use Spring Data JPA but I have not found information anywhere on wether it is possible to use it without Beans or the rest of the Spring framework.

Is this possible or should I try using another JPA?

推荐答案

从您的问题来看,我怀疑对Spring + Java持久性生态系统的误解很少:

From your question, I suspect there are few misunderstandings of Spring + Java persistence ecosystem:

  • 您可以在不使用Spring Boot的情况下使用Spring Data JPA(您需要使用Spring Core,因为它是Spring Data JPA依赖项),但对我来说这没有多大意义,因为Spring Boot为您提供了许多便捷的魔术和语法糖.
  • Spring + Spring Boot生态系统主要是针对Web应用程序量身定制的,但也可以用于非面向Web的应用程序.如果您正在编写桌面应用程序,则可能会使用某些桌面平台(例如Eclipse RCP).这些通常与Spring的依赖项注入不能很好地配合.您仍然可以使用其他独立的Spring + Spring Boot功能,但是缺少重要的Spring + Spring Boot主干-> IoC容器.
  • Spring Data JPA不是JPA提供程序.它只是JPA标准之上的便利层,可轻松将JPA ORM插入Spring应用程序.它还使用Spring Data项目家族中的类似模式,以使各种持久性存储对于Spring开发人员而言易于使用.
  • 如果您要使用JPA(与Spring生态系统分开的JEE标准API),则可以使用一些ORM(例如Hibernate,Toplink) 完全不使用Spring的JPA(javax.persistence)API.
  • You can use Spring Data JPA without Spring Boot (you need to use Spring Core because it is Spring Data JPA dependency), but it doesn't make much sense to me as Spring Boot gives you a lot of convenient magic and syntactic sugar.
  • Spring + Spring Boot ecosystem are primarily tailored towards web applications, but can be used for non-web facing applications as well. If you are writing desktop application, chances are you will be using some of the desktop platforms (e.g. Eclipse RCP). These often doesn't work well with Spring's dependency injection. You can still use other isolated Spring + Spring Boot features, but you are missing important Spring + Spring Boot backbone -> IoC container.
  • Spring Data JPA is not JPA provider. It is just convenience layer on top of JPA standard that makes it easy to plug JPA ORM into Spring applications. It also uses similar patterns from Spring Data projects family to make various persistence stores easy to use for Spring developers.
  • If you are looking ti use JPA (JEE standard APIs that are separate from Spring ecosystem), you can definitely use some ORM (e.g. Hibernate, Toplink) with JPA (javax.persistence) APIs without Spring altogether.

为回答您的问题,您有两种选择:

So to answer your question you have two options:

  1. 如果您使用某种Java桌面框架(例如Eclipse RCP或基于OSGi的某种东西),则完全不要使用Spring.您可能想将Toplink(来自Eclipse社区)或Hibernate与JPA API结合使用.
  2. 如果您要利用Spring IoC进行桌面应用程序开发,请绝对使用不带Web功能的Spring + Spring Boot + Spring Data JPA组合.

这篇关于在没有Spring Boot应用程序的情况下使用Spring Data JPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆