Spring boot start up Building JPA container very slow - java

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

Related

Hibernate time to first action - too slow

I started a new Java Spring Hibernate project. I only have a few POJO's for now. But hibernate's first actions (drop, create table etc.) happens too late, almost 30 seconds after project gets started.
As I said, there isn't much of a code right now. I'm very new at Java web development and Hibernate. This is my application.properties:
spring.datasource.url=jdbc:oracle:thin:#//localhost:1521/xe
spring.datasource.username=system
spring.datasource.password=*****
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.naming.physical-strategy=com.bmt311.dershane.CustomPhysicalNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
Why would you always recreate a database when developing locally? Oracle AFAIK does quite a lot of stuff(reserve diskspace etc.) when using DDL so it is generally a bad idea to use create-drop with Oracle. Try using spring.jpa.hibernate.ddl-auto=update instead for developing locally, or even better, use a dedicated tool for schema management like Liquibase or Flyway and use spring.jpa.hibernate.ddl-auto=none.

Flyway deprecation message logged when using Spring Boot 2

I use Spring Boot 2.0.4.RELEASE with Flyway 5.1.4. When starting my Spring Boot application I get the warning Flyway.setCallbacks(FlywayCallback) has been deprecated and will be removed in Flyway 6.0. Use Flyway.setCallbacks(Callback) instead.
This seems to be caused by Spring Boot as I don't configure any callbacks myself. Is there any way to disable this warning or prevent its root cause?
The problem is occurring because you are using Flyway 5.1 with Spring Boot 2.0. Spring Boot 2.0 compiles against, and provides dependency management for, Flyway 5.0 where the setCallbacks(FlywayCallback[]) has not been deprecated and does not generate a warning when called.
If you want to continue using Boot's auto-configuration then, at the time of writing, you have a couple of options:
Drop back to Flyway 5.0.x by remove your override of Flyway's version and allowing Spring Boot's dependency management to control the version.
Customise your logging configuration so that the warning isn't logged.
It should be possible to improve the situation in Spring Boot 2.0.x. Currently, setCallbacks(FlywayCallback[]) is called even when the array is empty. That's benign with Flyway 5.0, but unnecessarily generates the warning you are seeing with 5.1. This issue will address that.

JavaMelody brakes Spring Boot tests

The application is developed on Spring Boot 2.0.1.
I include the next dependency to be able to use JavaMelody -
dependency("net.bull.javamelody:javamelody-spring-boot-starter:1.72.0")
JavaMelody configuration:
javamelody:
advisor-auto-proxy-creator-enabled: false
init-parameters:
url-exclude-pattern: (/webjars/.*|/css/.*|/images/.*|/fonts/.*|/js/.*)
As a result I have a performance monitoring system and completely broken integration tests (JUnit version is 5).
The exception message is
the configured DataSource [com.sun.proxy.$Proxy128] (named '') is not the one associated with transaction manager [org.springframework.orm.jpa.JpaTransactionManager] (named '').
It can be fixed by removing javamelody dependency or by disabling javamelody in config file of the application.
Does somebody know the cause of the issue? Doesn't it create some unobvious bugs out of tests' scope?
I faced the same issue. I found a solution. I checked the Java melody jar file and they have a spring.factories in there. I think this might be messing around with the configurations.
In the application-test.properties I added this:
spring.autoconfigure.exclude=net.bull.javamelody.JavaMelodyAutoConfiguration
and it seems to work.
add
spring.autoconfigure.exclude=net.bull.javamelody.JavaMelodyAutoConfiguration
in application.properties can help.

Spring boot application startup stuck loading hibernate files

I am using spring boot application with hibernate to connect to postgressql, but when I am running my application with run as spring boot app the starting of server is stuck with loading hibernate files
without any error, I am stuck on this and it's not also showing any error.
Does anyone have any idea?
Add the following to your app properties
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
or in your code the below
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
Hope it helps!
There was another instance of Postgresql server was running and i was also not able to kiss the process that's why the application was stuck, i restarted my system and its working fine
If you are using JPA, check your repository configuration. Spring can spend a very long time scanning for JPA repositories if you don't have basePackages or basePackageClasses set in your #EnableJpaRepositories annotation (this can be added by JpaRepositoriesAutoConfiguration if your setup meets that class's #ConditionalOn requirements).

Liquibase execution order in Spring Boot

I was using spring-boot 1.0.1 and everything was fine.
Than I needed to upgrade to latest version 1.1.8.
As I see something with liquibase is changed and I cannot run application in the development mode normally.
The problem is that before updating first Hibernate was creating tables and performing database things, then Liquibase. Now Liquibase runs first and complains that there is no tables.
Is there a way how to solve this?

Categories