Why does Spring Boot application not exit gracefully? - java

I am running a Spring Boot application using bootRun task in Intellij (13.1.5 on Linux), and I am trying to shut down a listener thread in the lifecycle callback, however when stopping the app in IntelliJ, I find my listener thread is still running and logging.
In Console:
"Disconnected from the target VM, address: ..., transport: 'socket'
6:39:22 AM: External task execution finished 'bootRun'."
Then I did ps grep and kill the process,
only then console prints:
"2016-03-28 06:39:59.606 INFO 7740 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#657617e6: ...2016-03-28 06:39:59.611 INFO 7740 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown"
My Questions:
Why stopping app in Intellij not closing application context?
Accodring to Doc, Spring Web app automatically registers shutdown hooks. But I have tried #PreDestroy, destroyMethod, and implements LifeCycle, why does none of them get called?

Related

Spring Boot works on Other Local Computers but not mine IntelliJ, Bean Factory not working

I am using Spring Boot with IntelliJ Java 8. For some reason the Bean Factory is working on all other teammates computers from Git, except my local computer. I am receiving the following errors. It's like it cannot initialize the Beans. I cleared, invalidated caches, and restarted Intellij. Still no luck. Does anyone know what the issue can be?
2021-09-02 12:26:49.213 INFO 2430 --- [ main] c.k.s.s.c.capture.server.Application : Starting Application using Java 1.8.0_73 on KMAC-15SJGH5 with PID 2430 (/Users/joe/src/charge-capture/service/service-server/target/classes started by joe in /Users/joe/src/charge-capture)
2021-09-02 12:26:49.217 INFO 2430 --- [ main] c.k.s.s.c.capture.server.Application : No active profile set, falling back to default profiles: default
2021-09-02 12:26:51.689 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-09-02 12:26:51.690 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-09-02 12:26:51.721 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 16 ms. Found 0 JPA repository interfaces.
2021-09-02 12:26:51.742 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-09-02 12:26:51.744 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-09-02 12:26:51.768 INFO 2430 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 Redis repository interfaces.
2021-09-02 12:26:52.197 INFO 2430 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=43442f9b-fc6e-3ab1-be0d-b16685f5327e
2021-09-02 12:26:52.554 INFO 2430 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'com.abcd.library.springboot.autoconfigure.config.RedisCacheCon
This program does not have errors on other computers, and so its not a source code problem, more of an environmental issue with my local.
Active profiles does not seem like the issue, as it has a select mechanism here
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
String[] profiles = SpringProfilesUtil.readActiveProfiles(Application.class);
if(profiles != null) {
springApplication.setAdditionalProfiles(profiles);
}
springApplication.run(args);
}
I did not locate Maven Window even though the Plugin was installed.
Right Click on the root pom.xml file and select "Add as Maven Project" from the context menu. After this, application should run without Bean errors.
Not sure why it fixed the issue, however could be a small issue with IntelliJ. Either way, it works.

Getting error when upgrading spring boot from 2.2.2 to 2.3.2.RELEASE

I am upgrading from spring boot 2.2.2 to 2.3.2.RELEASE and getting below error. I am sure that it is not related to the port which is already in use. Also, I have changed the logging from logging.file to logging.file.name as per spring boot 2.3.2
WARN [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,317]- org.springframework.context.support.AbstractApplicationContext.refresh:Line 559 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException: Connector configured to listen on port 10090 failed to start
INFO [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,321]- org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.shutdown:Line 218 - Shutting down ExecutorService 'applicationTaskExecutor'
INFO [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,324]- com.zaxxer.hikari.HikariDataSource.close:Line 350 - HikariPool-1 - Shutdown initiated...
INFO [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,329]- com.zaxxer.hikari.HikariDataSource.close:Line 352 - HikariPool-1 - Shutdown completed.
INFO [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,329]- com.zaxxer.hikari.HikariDataSource.close:Line 350 - HikariPool-2 - Shutdown initiated...
INFO [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,337]- com.zaxxer.hikari.HikariDataSource.close:Line 352 - HikariPool-2 - Shutdown completed.
INFO [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-20 15:22:29,353]- org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener.logMessage:Line 136 -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
ERROR [framework_5_5][traceId:][spanId:][parentSpanId:][spanExportable:][bt:#build.time#][cbn:#current.branch#][main][2020-08-13 19:20:31,769]- org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report:Line 40 -
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 10090 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 10090, or configure this application to listen on another port.
configure this application to listen on another port.
Above errors occurs when application is already running.
If you are using Eclipse or Intellij, could restart and run the application.
As i am not allowed to enter comment putting it here?
What is the solution for this.
I have added
((AbstractAjpProtocol<Long>)ajpConnector.getProtocolHandler()).setSecretRequired(false);
with ajp connector and issue is resolved
Updated:
You need to add this line of code to make it work with apache
protocol.setAddress(new InetSocketAddress(0).getAddress());
Port zero will let the system pick up an ephemeral port in a bind operation

Cant run spring boot application?

I'm working on an assignment with a team. And my team decided to use spring boot for the application. However for some reason whenever I run the application I get a different message on my terminal whereas my teammates have a different message on their terminal. Instead of "LiveReload server is running on port 35729" They get "tomcat initialized with port(s) 8081 (http)".
I am not sure what exactly to do since all of us are using the same project and I have built it as they told me to do so.
However it is still not working for me. Can anybody tell me how to fix it so I could get it to run. I have never used maven or spring boot before.
This is the message I am getting on my terminal
2020-06-13 23:05:35.538 INFO 34396 --- [ restartedMain] com.rest.WebApplication : Starting WebApplication on DESKTOP-1M4A445 with PID 34396 (Directory\project\target\classes started by USER in Directory/project)
2020-06-13 23:05:35.543 INFO 34396 --- [ restartedMain] com.rest.WebApplication : No active profile set, falling back to default profiles: default
2020-06-13 23:05:35.609 INFO 34396 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-06-13 23:05:36.520 INFO 34396 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-06-13 23:05:36.550 INFO 34396 --- [ restartedMain] com.rest.WebApplication : Started WebApplication in 1.452 seconds (JVM running for 2.035)
Process finished with exit code 0
Thank you so much.
It seems you have spring-boot-devtools dependency in the classpath. Because of this you see LiveReload server is running on port 35729 statement written to log.
From your logs, it seems tomcat is not started at all. Verify your properties files and make sure web environment is not turned off
For spring-boot 1.x, look for spring.main.web-environment=false property
For spring-boot 2.x, look for spring.main.web-application-type=none property

which tomcat service gets started while running a jar from terminal

As i had created a jar from my project, i had started running it from linux terminal using the command
java -jar snapShot.jar
By running this my project works fine and gives console output as
INFO 2018-06-26 13:34:25 [main] -Registering beans for JMX exposure
on startup
INFO 2018-06-26 13:34:25 [main] -Tomcat started on port(s): 8080
(http)
INFO 2018-06-26 13:34:25 [main] -Started DomainApplication in 12.143
seconds (JVM running for 12.662)
I have another Tomcat in my local system. Apache Tomcat Version 8.5.29 .
But while running the jar file in terminal i found another tomcat service is running. Actually which gets started?

Investigate why Spring Boot service hangs (freeze) on service shutdown (SIGINT)

I have a Spring Boot executable application - It's REST webservice. Service is working well, but when I try to gracefully shutdown it (by issuing process interrupt - SIGINT), service "hangs" and is still running. Here is log after shutdown command (red square stop button in Intellij IDEA):
Disconnected from the target VM, address: '127.0.0.1:36656', transport: 'socket'
2016-10-28 11:15:26.369 INFO 5429 --- [ Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#160ac7fb: startup date [Thu Oct 27 18:32:46 CEST 2016]; root of context hierarchy
Red stop button changes to skull (when clicked, SIGKILL is sent and process is immediatelly dead)
Apparently, something (resource?) is blocking closing of spring context and exiting application normal way.
My question is: How can I investigate what is wrong? What is the cause of blocking?
Dependencies of project:
spring-boot-starter-parent 1.4.1.RELEASE
spring-boot-starter-web
com.oracle:ojdbc6
com.thoughtworks.xstream:xstream
and some commons
Btw, service is running on Oracle Java "Java(TM) SE Runtime Environment (build 1.8.0_111-b14)" and on Ubuntu 16.04.1 LTS (and will run on production also)
I suspect xstream library, but I don't know how to find out. I would appreciate any suggestions.

Categories