Skip to content
Advertisement

Use Spring Data JPA without Spring Boot application


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?

Advertisement

Answer

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

  • 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 to 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. If you are using some kind of Java desktop framework (e.g. Eclipse RCP or something OSGi based), do not use Spring at all. You probably want to use Toplink (which comes from Eclipse community) or Hibernate with JPA APIs.
  2. If you are doing desktop application for which make sense to take advantage of Spring IoC, definitely use Spring + Spring Boot + Spring Data JPA combo without web features.
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement