java - Spring boot启动构建JPA容器非常慢

标签 java spring-boot spring-data-jpa

我正在将 Spring Boot 与 JPA 结合使用,最近它开始需要很长时间才能启动。它总是卡在控制台的这一行大约 5 分钟:

Building JPA container EntityManagerFactory for persistence unit 'default'

我看过这个相关帖子:
Very slow Spring Boot application startup
并尝试将 spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false 添加到我的 application.properties
但这根本没有什么区别。

有什么方法可以调试 spring boot 在这段时间实际上在做什么吗? 我的 gradle 依赖项如下:

compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.session:spring-session:1.3.1.RELEASE')
compile('mysql:mysql-connector-java')
compile('org.apache.commons:commons-lang3:3.7')
compile('com.google.cloud:google-cloud-storage:1.14.0')
compile('javaxt:javaxt-core:1.8.1')
compile('org.hibernate:hibernate-envers:5.0.12.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')

我正在使用 Spring Boot 版本 1.5.9.RELEASE

我的application.properties有这个:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://notreal.server.com:3306/testdb
spring.datasource.username=NotRealUser
spring.datasource.password=NotRealPwd
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

非常感谢任何建议/帮助。

最佳答案

我通过在 application.properties 中设置 spring.jpa.hibernate.ddl-auto=none(之前设置为 auto)成功解决了我的问题。

我认为这会阻止 Hibernate 尝试将对象模型与数据库中的表进行比较。之后Springboot启动就快多了。

我应该提到的是,那时我们还在项目中添加了 Hibernate Envers(审计框架),该项目在数据库中生成了一堆新表。所以这可能使问题变得更加复杂。

关于java - Spring boot启动构建JPA容器非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52510523/

相关文章:

java - 无法订阅 Mono<XXX> spring webflux

postgresql - 错误 : operator does not exist: timestamp without time zone >= boolean Hint: No operator matches the given name and argument type(s)

java - Spring HttpRequest 获取父 URL

java - 在 Java 中使用 POI 时如何增加 Excel 计算引擎的限制?

java - 将 jtable 选择的 "ctrl + space"行为分配给另一个键

java - Spring Boot中方法调用的标准输出重定向的另一种方式

java - 如何在 Eclipse 上调试远程部署的 Spring Boot 应用程序和 Maven

java - Spring Data JPA @Convert 抛出不允许操作异常

spring-mvc - 使用 Spring MVC、JPA 和数据表进行分页

java - session 超时在 Google App Engine 上不起作用