我正在将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
任何建议/帮助都值得赞赏。
答案 0 :(得分:0)
我设法通过在 application.properties 中设置spring.jpa.hibernate.ddl-auto=none
(以前设置为auto
)来解决问题。
我认为这可以防止Hibernate尝试将对象模型与数据库中的表进行比较。之后,Springboot的启动要快得多。
我应该提到,那时我们还向项目添加了 Hibernate Envers (审核框架),该项目在数据库中生成了一堆新表。因此,这可能使问题更加复杂。
答案 1 :(得分:0)
在Hashicorp Nomad内部也有同样的问题。适用于任何分配内存的系统。
如果查看系统日志(不是Spring Apps),则会发现此步骤占用更多的内存。增加应用程序的内存,它应与2