简体   繁体   中英

Spring boot start up Building JPA container very slow

I am using Spring Boot with JPA and it has recently started to take a long time to start up. It always gets stuck on this line in the console for about 5 minutes:

Building JPA container EntityManagerFactory for persistence unit 'default'

I have seen this related post:
Very slow Spring Boot application startup
And have tried adding spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false to my application.properties
But this made no difference at all.

Is there any way to debug what spring boot is actually doing during this time? My gradle dependencies are as follows:

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')

And I am using Spring Boot version 1.5.9.RELEASE

My application.properties has this:

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

Any suggestions / help much appreciated.

I managed to fix my problem by setting spring.jpa.hibernate.ddl-auto=none in my application.properties (previously set to auto ).

I think this prevents Hibernate trying to compared object models with tables in the database. Springboot start-up was much quicker afterwards.

I should mention that around then we also added Hibernate Envers (auditing framework) to the project which generated a bunch of new tables in the database. So this probably compounded the issue.

Had the same issue within Hashicorp Nomad. Would apply on any system that allocates memory.

If you look at the system logs (not Spring Apps) you will see this step is more memory intensive. Increase memory for the application and it should run with spring.jpa.hibernate.ddl-auto=auto

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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