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).
Related
I understand how SpringBoot saves time in other respects such as having an embedded server and starter dependencies, but how does SpringBoot reduce boiler plate code needed for an application?
Thanks
Spring Boot brings a ton of autoconfiguration classes, which create beans with default configurations, that would have been created by the developer themselves previously. An example would be beans for database access. You would have created a datasource, maybe a JdbcTemplate, connection pool etc. Now those beans are created with autoconfiguration (example: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java), and configuration can be customized through application.properties files.
Spring boot comes with starters and through maven you can search for the required dependency and add it to your project it supports rapid development and below are some key features of spring boot
Removes boilerplate code of application setup by having embedded web
server(Tomcat) and in memory db.
Auto configuration of application context.
Automatic servlet mappings.
Embedded database support(h2)
Automatic controller mapping
You can look at Spring Boot as an opinionated distribution of Spring. It comes with sane defaults and machanisms to hide the boilerplate while still making changes to those defaults possible.
When you use annotations #SpringBootApplication, Spring boot takes care of creating all the beans required for running WebServer and injecting it using its Dependency Injection feature.
#SpringBootApplication is alone equivalent to below three annotations.
#Configuration : You can define your own configuration class to register your beans in application context.
2.#EnableAutoConfiguration : Spring automatically creates beans available on your classs path using this feature.More details are available here.
#ComponentScan : Scans the current and base package where your application class lies.
It Creates ApplicationContext which contains all the necessary beans, ServletWebServerApplicationContext is one such bean created which takes care of initializing and running a WebServer by looking for ServletWebServerFactory bean(provides the webServer) within the ApplicationContext.
There is lot more going on behind the scene. Here is a video which explains it in details.
https://youtu.be/uCE3x4-GQ0k
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.html
I know that this is a very trivial question but please suggest me to find the way. Sometimes when I start Spring Boot server, it stops but it does not display the complete error/exception stack trace. Think of situation that spring boot server has been started in 8080 port and if somebody starts in 8080 port, it should clearly display that java.net.BindException. But in my case server simply aborts.
I normally find the issue from the IDE like eclipse/Idea when I start the server in debug mode. But how to find the error when somebody starts spring boot server using command prompt ? There may be many errors for which spring boot is unable to start. My question is what configurations should be added in application.properties to know more details about the error/s for which spring boot is not getting started. Currently I am using Spring Boot 2.1.1.RELEASE version. Please help me fix this.
To see more details of the actions being carried out for a spring boot application, change the log level to debug. You can do it just by simply adding below lines in application.property/yaml file.
logging.level.=DEBUG
Or for web applications you can try
logging.level.org.springframework.web: DEBUG
Add the below property in application.xml - worked in Spring boot 2.2.4
logging.level.root:ERROR
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 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.
I'm running a Spring Boot application.
When there's no application.properties file in standard config paths it is not loaded and default configuration seems to be loaded.
application.properties:
spring.datasource.url=jdbc:sqlserver:...
Because of that, Spring Boot creates empty database with scheme without data which leads to empty program output.
How can one prevent Spring Boot from loading database default configuration?
you can use something as follows exclude in #EnableAutoConfiguration annotations to exclude Datasource default configuration. Reference
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
I don't know if there is any provision to make the app fail fast.
In order to stop Spring-Boot from autoconfiguring certain features for you, you need to explicitly exclude the corresponding class from the auto-configuration config:
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
Note: using this annotation you are taking back the responsibility from Spring to setup things for you, so you need to configure your DB properly from now on.