Running Spring Boot Admin with a non-default port - spring

I want to start the Spring Boot Admin server on a different port than 8080.
So I configured the server.port property in the bootstrap.yml file with 9000, but still the server listens on port 8080 according to the log file.
Here's my bootstrap.yml:
server:
port: 9000
spring:
application:
name: admin-server
cloud:
config:
uri: http://localhost:8888
And this is the final part of the console log:
2018-11-29 15:52:11.242 INFO 25999 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-11-29 15:52:11.271 INFO 25999 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-29 15:52:11.274 INFO 25999 --- [ main] n.d.d.c.a.AdminServerApplication : Started AdminServerApplication in 2.826 seconds (JVM running for 3.355)
2018-11-29 15:52:11.818 INFO 25999 --- [on(4)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-11-29 15:52:11.819 INFO 25999 --- [on(4)-127.0.0.1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-11-29 15:52:11.830 INFO 25999 --- [on(4)-127.0.0.1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 11 ms

In the application.properties file put this
server.port = 9000

A flashlight in my brain told me I might have forgotten to add the spring-cloud-config-client dependency, after checking, and then adding the appropriate dependency to the pom.xml, it worked like a charm:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
Thanks to all for providing feedback.

Many different configuration sources have precedence over application.properties (or YAML) as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
You might need to verify if one of those sources are not interfering with the value of serve.port.

Related

Clone of start.spring.io

I'm trying to build an instance of start.spring.io to use it in an air-gaped network. I have been working on it for three weeks and still I don't understand well what to do.
I have cloned start.spring.io from GitHub in a host connected to Internet.
There I can build the application without errors:
./mvnw clean install -DskipTests=true
Then if I true to run the application (../mwnw spring-boot:run from the start-site directory), I get the following error when the application starts, I mean is not an error trying to generate a project, and the application dies:
2022-12-19 17:53:21.170 INFO 2701 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-12-19 17:53:21.264 WARN 2701 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [io.spring.initializr.web.controller.ProjectGenerationController] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#5cb0d902]
2022-12-19 17:53:21.272 INFO 2701 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-12-19 17:53:21.311 INFO 2701 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-12-19 17:53:21.411 ERROR 2701 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [io.spring.initializr.web.controller.ProjectGenerationController] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#5cb0d902]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.23.jar:5.3.23]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$
...
So, I am not adding any special dependencies or initilializr dependencies other than those already included in the project. I use Java 17 from Bell Soft.
I am not about the Spring Boot version but I haven't modified anything in the project. The pom file in the top directory includes:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
</parent>
About my dependencies I am using the initializer-bom:0.20.0-SNAPSHOT. I have also tried with other versions like 0.13.0 and 0.12.0 but the build fails in both cases for the start-site:
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /workspaces/start.spring.io.ori/start-site/src/main/java/io/spring/start/site/extension/dependency/springcloud/SpringCloudContractKotlinDslGradleBuildCustomizer.java:[44,22] cannot find symbol
symbol: method snippets()
location: variable build of type io.spring.initializr.generator.buildsystem.gradle.GradleBuild
[ERROR] /workspaces/start.spring.io.ori/start-site/src/main/java/io/spring/start/site/extension/dependency/graalvm/HibernatePluginGroovyDslGradleBuildCustomizer.java:[39,22] cannot find symbol
symbol: method snippets()
location: variable build of type io.spring.initializr.generator.buildsystem.gradle.GradleBuild
[ERROR] /workspaces/start.spring.io.ori/start-site/src/main/java/io/spring/start/site/extension/dependency/springcloud/SpringCloudContractGroovyDslGradleBuildCustomizer.java:[36,22] cannot find symbol
symbol: method snippets()
location: variable build of type io.spring.initializr.generator.buildsystem.gradle.GradleBuild
[INFO] 3 errors
I wonder if this effort makes sense. If I manage to build the application, will I be able of generating code or does the application connect to somewhere else to retrieve the data required to generate the code?
I would appreciate any hints. Thanks
I will write my (potential) answer here, even though I don't really think that is a real answer but too big to make it as a comment.
My setup:
Amazon Coretto JDK 17 https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html (it is not JDK 17 from Bell Soft)
Windows 11 Home
So I went to https://github.com/spring-io/start.spring.io and cloned it.
git clone https://github.com/spring-io/start.spring.io.git
Then I went in the root directoy of the cloned project and ran following command:
./mvnw clean install
Here I got some errors while running the tests, but this shouldn't be way too tragic - I think they failed for me, because it tries to run some gradlew commands but they do fail, because I don't have Gradle installed on my PC, as I am always using the Gradle Wrapper.
Then I started the Spring Boot Application.
cd start-site
../mvnw spring-boot:run
The Spring Boot Application started:
022-12-20T15:01:03.510+01:00 INFO 16592 --- [ restartedMain] io.spring.start.site.StartApplication : No active profile set, falling back to 1 default profile: "default"
2022-12-20T15:01:03.573+01:00 INFO 16592 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-12-20T15:01:03.573+01:00 INFO 16592 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-12-20T15:01:04.800+01:00 INFO 16592 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-20T15:01:04.809+01:00 INFO 16592 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-20T15:01:04.810+01:00 INFO 16592 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-20T15:01:04.872+01:00 INFO 16592 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-20T15:01:04.873+01:00 INFO 16592 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1298 ms
2022-12-20T15:01:05.371+01:00 INFO 16592 --- [ restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-12-20T15:01:05.823+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.metadata' created in EhcacheManager.
2022-12-20T15:01:05.832+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.metadata
2022-12-20T15:01:05.832+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.metadata
2022-12-20T15:01:05.835+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.dependency-metadata' created in EhcacheManager.
2022-12-20T15:01:05.836+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.dependency-metadata
2022-12-20T15:01:05.836+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.dependency-metadata
2022-12-20T15:01:05.839+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.project-resources' created in EhcacheManager.
2022-12-20T15:01:05.841+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.project-resources
2022-12-20T15:01:05.841+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.project-resources
2022-12-20T15:01:05.843+01:00 INFO 16592 --- [ restartedMain] org.ehcache.core.EhcacheManager : Cache 'initializr.templates' created in EhcacheManager.
2022-12-20T15:01:05.843+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheConfiguration,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.templates
2022-12-20T15:01:05.844+01:00 INFO 16592 --- [ restartedMain] org.ehcache.jsr107.Eh107CacheManager : Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=urn.X-ehcache.jsr107-default-config,Cache=initializr.templates
2022-12-20T15:01:06.026+01:00 INFO 16592 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2022-12-20T15:01:06.031+01:00 INFO 16592 --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2022-12-20T15:01:06.078+01:00 INFO 16592 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-20T15:01:06.089+01:00 INFO 16592 --- [ restartedMain] io.spring.start.site.StartApplication : Started StartApplication in 3.056 seconds (process running for 3.444)
2022-12-20T15:01:17.890+01:00 INFO 16592 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-12-20T15:01:17.891+01:00 INFO 16592 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-12-20T15:01:17.892+01:00 INFO 16592 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2022-12-20T15:01:18.122+01:00 INFO 16592 --- [io-8080-exec-10] .s.SaganInitializrMetadataUpdateStrategy : Fetching Spring Boot metadata from https://spring.io/project_metadata/spring-boot
If I now call http://localhost:8080/ - it works, I didn't do absolutely nothing.
Could it maybe be your JDK? I mean the JDKs are similar but not the same... And you also asked:
I wonder if this effort makes sense. If I manage to build the
application, will I be able of generating code or does the application
connect to somewhere else to retrieve the data required to generate
the code? I would appreciate any hints. Thanks
I personally think, it could make sense but - as soon as I generated a project on my own Spring Initializr, I watched the console of the Spring Boot Application and could see the following log:
Fetching Spring Boot metadata from https://spring.io/project_metadata/spring-boot
So it looks, like this thing actually fetches data from the internet, now I don't know what options you have but I have two in mind.
You could try to fork the GitHub Project and try to remove this network call (if this is really the only one) - I couldn't see anything more in the logs atleast... The actual response of the Call looks pretty simple though:
{"id":"spring-boot","name":"Spring Boot","projectReleases":[{"version":"3.0.1-SNAPSHOT","versionDisplayName":"3.0.1-SNAPSHOT","current":false,"releaseStatus":"SNAPSHOT","snapshot":true},{"version":"3.0.0","versionDisplayName":"3.0.0","current":true,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.7.7-SNAPSHOT","versionDisplayName":"2.7.7-SNAPSHOT","current":false,"releaseStatus":"SNAPSHOT","snapshot":true},{"version":"2.7.6","versionDisplayName":"2.7.6","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.6.14","versionDisplayName":"2.6.14","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.5.14","versionDisplayName":"2.5.14","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false},{"version":"2.4.13","versionDisplayName":"2.4.13","current":false,"releaseStatus":"GENERAL_AVAILABILITY","snapshot":false}]}
You allow explicitly the URL https://spring.io/project_metadata/spring-boot to fetch data inside of your Air Gap Network (I don't know if this is viable though)
I hope this helps a bit?
There are many dependencies that start from the initializer for spring-boot. If you try to build within an air-gapped network, you will not have access to maven's repository for the dependencies. Try building the package outside the network, and capture the libraries required. Look to your ~/.m2/ folder for the copies of the libraries needed. I would recommend setting up a Nexus repository, and it will capture the libraries as you need them from an open network which you can then use on the air-gapped network.
If this is a secured network, you'll have to have all those files vetted and scanned before you can get them into the air-gapped network. Plan for this.
As you add additional annotations or dependencies, you will have to get them from maven central again. It's not ideal, but you might find someone who setup a project to include all spring-boot dependencies for just this situation.
Also, use the STS dev environment, and build your spring-boot to run with included libraries.

Could not reach the docker container web application even it run successfully

I wrote a simple backend application by spring boot and kotlin, here you can see the full settings https://github.com/lifeodyssey/demo
this bug performed as
I can start and access the application by ./gradlew bootRun
I can start and access the application by java -jar demo.jar
But I could not access the application when I try to start it in a container, even I can see a successful log by docker logs containerID. The log is given below
2022-11-12 15:50:33.017 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : Starting DemoApplicationKt using Java 11.0.16 on eeb1dfe09e6a with PID 1 (/Demo-0.0.1.jar started by root in /)
2022-11-12 15:50:33.029 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : No active profile set, falling back to 1 default profile: "default"
2022-11-12 15:50:34.315 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
2022-11-12 15:50:34.320 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2022-11-12 15:50:34.346 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 15 ms. Found 0 MongoDB repository interfaces.
2022-11-12 15:50:35.564 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8000 (http)
2022-11-12 15:50:35.595 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-11-12 15:50:35.596 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-11-12 15:50:35.787 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-11-12 15:50:35.788 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2628 ms
2022-11-12 15:50:38.155 WARN 1 --- [ main] o.s.b.a.m.MustacheAutoConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Mustache configuration, or set spring.mustache.check-template-location=false)
2022-11-12 15:50:38.346 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8000 (http) with context path ''
2022-11-12 15:50:38.412 INFO 1 --- [ main] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 6.588 seconds (JVM running for 7.745)
And here is the Dockerfile
FROM openjdk:11
COPY /build/libs/demo-0.0.1-SNAPSHOT.jar Demo-0.0.1.jar
EXPOSE 8000
ENTRYPOINT ["java","-jar","/Demo-0.0.1.jar"]
Here is the commmand I used to build image and run container
docker build -t demo .
docker run -dp 8000:8000 demo:latest
I could not find where is the problem. Can you help me with it ?
Update
Thanks for the comments below, here is what showed when I access localhost
This site can’t be reached localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
I have tried change -dp 8000 to -d -p 8000, but nothing changed.
Try to connect to it using 127.0.0.1:8000 instead of localhost:8000, maybe localhost is not resolving to 127.0.0.1.
If not try a different port and/or browser. Finally your firewall might be blocking your server so check that.
I finally found the issue.
I installed two application two run my docker. One is colima, another is Docker Desktop.
I guess the problem is that docker do not know which one is the "localhost".
This problem fixed after I uninstall docker desktop and link docker to colima.

Unable to call Spring Boot API inside Ubuntu WSL2 at localhost:8080 using Postman

I am having trouble calling and posting to an API build with Spring Boot inside a WSL2 Ubuntu environment. I can run the project and it gets initialized at port 8080 as shown in the logs:
:: Spring Boot :: (v2.7.4)
2022-10-14 16:18:11.033 INFO 32139 --- [ main] com.example.demo3.Demo3Application : Starting Demo3Application using Java 17.0.4 on LCE50469 with PID 32139 (/home/joschenk/ModelAPI/target/classes started by joschenk in /home/joschenk/ModelAPI)
2022-10-14 16:18:11.036 INFO 32139 --- [ main] com.example.demo3.Demo3Application : No active profile set, falling back to 1 default profile: "default"
2022-10-14 16:18:11.716 INFO 32139 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-10-14 16:18:11.722 INFO 32139 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-10-14 16:18:11.722 INFO 32139 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-10-14 16:18:11.779 INFO 32139 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-10-14 16:18:11.779 INFO 32139 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 703 ms
2022-10-14 16:18:12.005 INFO 32139 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-10-14 16:18:12.012 INFO 32139 --- [ main] com.example.demo3.Demo3Application : Started Demo3Application in 1.227 seconds (JVM running for 1.655)
When now trying to Post to the API using Postman with
POST http://localhost:8080/api/v1/model
I am getting the following response:
Error: connect ECONNREFUSED 127.0.0.1:8080
Request Headers
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.2
Accept: */*
Postman-Token: 846f27f6-f2e6-4d0f-9554-3fdb3f352bc9
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Can someone help here? Thanks!
I solved the issue by running a wsl2 kernel update inside the Windows Powershell. I then rebooted everything and now it works.
wsl --update
wsl --shutdown

Vaadin 23 Flow - Spring Boot - Live Reload not working

I recently updated my Vaadin Flow Project to the newest Version 23.0.1.
It all did great, but the LiveReload (detecting Java-FileChanges) doesnt work at all (Its detecting only CSS changes).
I created a new Spring Boot Vaadin 23 Project with Spring-Initializr to check if it's the same problem. I followed the LiveReload Section in the official Vaadin Docs, but it does'nt work at all... :(
My Console shows no errors at all..
Does someone have a similar Problem?
Console Output:
2022-03-21 12:28:33.379 INFO 16300 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
[.....]
2022-03-21 12:28:33.814 INFO 16300 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
2022-03-21 12:28:33.827 INFO 16300 --- [ restartedMain] n.b.p.s.PlatonStartupApplicationListener : Initialize Application
2022-03-21 12:28:33.828 INFO 16300 --- [ restartedMain] n.b.p.s.PlatonStartupApplicationListener : Load global catalog.
2022-03-21 12:28:33.987 INFO 16300 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-21 12:28:33.988 INFO 16300 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-21 12:28:33.992 INFO 16300 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2022-03-21 12:28:38.306 INFO 16300 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : [build-status] : Compiled.
←[38;5;35m
----------------- Frontend compiled successfully. -----------------
←[0m2022-03-21 12:28:38.313 INFO 16300 --- [onPool-worker-3] c.v.b.devserver.AbstractDevServerRunner : Started Webpack. Time: 9897ms
2022-03-21 12:28:38.382 INFO 16300 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : No issues found.

Very slow Spring Boot application startup

I have a simple Spring Boot application that connects to a PostgreSQL database and serves as a JSON service. Somehow the startup has become very slow, see timings 10:37:10 and 10:38:00:
2015-05-09 10:37:09.649 INFO 20880 --- [lication.main()] o.apache.catalina.core.StandardService : Starting service Tomcat
2015-05-09 10:37:09.651 INFO 20880 --- [lication.main()] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.20
2015-05-09 10:37:09.767 INFO 20880 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2015-05-09 10:37:09.767 INFO 20880 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2970 ms
2015-05-09 10:37:09.979 INFO 20880 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-05-09 10:37:09.985 INFO 20880 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-05-09 10:37:10.105 INFO 20880 --- [lication.main()] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: org.postgresql.Driver
2015-05-09 10:37:10.214 INFO 20880 --- [lication.main()] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2015-05-09 10:37:10.233 INFO 20880 --- [lication.main()] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2015-05-09 10:37:10.585 INFO 20880 --- [lication.main()] org.hibernate.Version : HHH000412: Hibernate Core {4.3.8.Final}
2015-05-09 10:37:10.587 INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2015-05-09 10:37:10.589 INFO 20880 --- [lication.main()] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2015-05-09 10:37:10.968 INFO 20880 --- [lication.main()] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2015-05-09 10:38:00.023 INFO 20880 --- [lication.main()] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2015-05-09 10:38:00.041 INFO 20880 --- [lication.main()] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2015-05-09 10:38:00.274 INFO 20880 --- [lication.main()] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
Any thoughts? Is there anything I can do to diagnose the problem?
For Spring Boot you can set this in your application.properties file:
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
I also found that I needed to set another property or I would get the error "org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set". To rectify that I set this property:
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
This reduced our startup time from about 100 seconds down to 12.
Problem solved using
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
Thanks all.
Contributing application.yml version of property setting.
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
When I point to database in AWS RDS server it takes 78 seconds.
After given this configuration it takes 52 seconds.
spring:
jpa:
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
And after given this configuration with the above configuration it takes only 10 seconds.
spring:
jpa:
hibernate:
ddl-auto: none
For dev environment, use the following property
spring.jpa.hibernate.ddl-auto=none
This would be a bit risky for staging and prod environment.
Are you running the tests on a local server? Perhaps there's some problem with the database server URL, such as a non-resolvable hostname or an IPv6 DNS entry, connecting with the same connection string from another application (e.g. http://squirrel-sql.sourceforge.net/) could confirm the problem.
The delay is definitely logged when creating the database connection for the first time (either while loading the driver or performing the connection).
I found the startup takes long time when the db server is far, in my case it won't take time when using the localhost db, and it take about 20 seconds in product enviroment with db is in us and server is in jp.
For springboot data JPA you need to add spring.data.jpa.repositories.bootstrap-mode=lazy in application.properties file this would also reduce bootup time.
spring.data.jpa.repositories.bootstrap-mode=lazy
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
I used the following piece of code
spring:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
show-sql: false
generate-ddl: true
**hibernate:
ddl-auto: none
properties:
hibernate.hbm2ddl.auto: none**

Resources