如何使用EntityManager实现Spring Boot

时间:2018-04-18 15:28:51

标签: spring-boot

我是Spring Boot的新手,我在Spring Boot中看到默认使用JpaRepository进行数据库操作但是我想使用EntityManager,我在applicaition.properties文件中使用了以下设置。

spring.datasource.url= jdbc:mysql://xxxx:3306/my_db?useSSL=false&UseUnicode=true&characterEncoding=UTF-8
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto = none

当我尝试部署我的Spring Boot应用程序时,它会立即停止而不会抛出任何异常。

1 个答案:

答案 0 :(得分:0)

您需要稍微更改配置,

如下所示

spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username = xxxx
spring.datasource.password = xxxx
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.properties.hibernate.hbm2ddl.auto=create

有关更多详细信息,请参阅以下链接,这是常见的SpringBoot属性

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html