简体   繁体   English

Spring Data JPA是否需要Spring Boot?

[英]Does Spring Data JPA require Spring Boot?

I'd like to write a small example program with Spring Data JPA. 我想用Spring Data JPA编写一个小的示例程序。

Is Spring Boot a requirement to use this spring project? 使用Spring Boot是否需要使用Spring Boot?

No, you are perfectly fine to use Spring Data JPA by itself. 不,您完全可以单独使用Spring Data JPA。

Do note that Spring Boot makes it easier to set up a project, all Spring Data JPA examples use: 请注意,Spring Boot使创建项目更加容易,所有Spring Data JPA示例都使用:

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

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. 您可以使用不带启动模块的Spring,但在这种情况下,您必须考虑构建一个包含Spring Core + Data + JPA的项目,并在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. 如果您只是像上面说的那样做一个小例子,Spring Boot + Data + JPA可能会更快,更容易设置和运行。

After trying, I found it is possible to use Spring Data JPA with plain Spring, without spring boot. 尝试之后,我发现可以将Spring Data JPA与纯Spring一起使用,而无需使用Spring Boot。

When not using boot, the following are needed: 不使用引导时,需要以下内容:

1) spring-core maven dependency 1)Spring-core Maven依赖

2) spring-context dependency 2)弹簧上下文依赖

3) spring-data-jpa dependency 3)spring-data-jpa依赖

4) hibernate-entitymanager or some other JPA provider 4)Hibernate-entitymanager或其他一些JPA提供程序

5) mysql-connector-java or some other DB connector 5)mysql-connector-java或其他一些数据库连接器

6) javax.persistence-api dependency 6)javax.persistence-api依赖性

7) AnnotationConfigApplicationContext instead of SpringBootApplication 7)AnnotationConfigApplicationContext代替SpringBootApplication

8) @EnableJpaRepositories("mypackage") 8)@EnableJpaRepositories(“ mypackage”)

9) @ComponentScan("mypackage") 9)@ComponentScan(“ mypackage”)

10) @Bean for LocalContainerEntityManagerFactoryBean and dataSource 10)@Bean用于LocalContainerEntityManagerFactoryBean和dataSource

11) Setting Hibernate properties to EntityManager 11)将Hibernate属性设置为EntityManager

12) @Bean for PlatformTransactionManager 12)@Bean for PlatformTransactionManager

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM