Gonen I
Gonen I

Reputation: 6127

Does Spring Data JPA require Spring Boot?

I'd like to write a small example program with Spring Data JPA.

Is Spring Boot a requirement to use this spring project?

Upvotes: 2

Views: 4064

Answers (3)

Gonen I
Gonen I

Reputation: 6127

After trying, I found it is possible to use Spring Data JPA with plain Spring, without spring boot.

When not using boot, the following are needed:

1) spring-core maven dependency

2) spring-context dependency

3) spring-data-jpa dependency

4) hibernate-entitymanager or some other JPA provider

5) mysql-connector-java or some other DB connector

6) javax.persistence-api dependency

7) AnnotationConfigApplicationContext instead of SpringBootApplication

8) @EnableJpaRepositories("mypackage")

9) @ComponentScan("mypackage")

10) @Bean for LocalContainerEntityManagerFactoryBean and dataSource

11) Setting Hibernate properties to EntityManager

12) @Bean for PlatformTransactionManager

Upvotes: 6

Zorglube
Zorglube

Reputation: 734

You can use Spring without Boot module but, in your case, you'll have to consider building an project containing Spring Core + Data + JPA and run it inside an Application Server.

If you just do some small example, like you said, Spring Boot + Data + JPA might be faster and easier to setup and run.

Upvotes: 0

Karol Dowbecki
Karol Dowbecki

Reputation: 44962

No, you are perfectly fine to use Spring Data JPA by itself.

Do note that Spring Boot makes it easier to set up a project, all Spring Data JPA examples use:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Upvotes: 2

Related Questions