8

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.

  1. In Console:

    "Disconnected from the target VM, address: ..., transport: 'socket' 6:39:22 AM: External task execution finished 'bootRun'."

  2. 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:

  1. Why stopping app in Intellij not closing application context?
  2. 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?
Ilya Lysenko
  • 1,772
  • 15
  • 24
yuyu33
  • 185
  • 2
  • 8
  • I am having the same issue. You're supposed to click the Exit icon (see http://stackoverflow.com/questions/4727536/how-do-i-stop-a-processing-running-in-intellij-such-that-it-calls-the-shutdown-h) instead of Stop in order to get a graceful shutdown, but it still doesn't call my @PreDestroy method. I have also tried implementing DisposableBean and creating an applicationListener (http://stackoverflow.com/questions/26678208/spring-boot-shutdown-hook). Nothing works! – JakeRobb Apr 07 '16 at 22:50
  • @JakeRobb I'm not sure that will work. OP is executing bootRun which is a task you get out of the box with spring boot. Due to the nature of spring boot the web server is embedded and thus intellij won't be awere that a web server is even running. All it would see is a running gradle task as it makes a JAR not a WAR – Stewart Jan 03 '19 at 07:16
  • Yes, as I said, it doesn’t work. I wasn’t suggesting a solution. – JakeRobb Jan 03 '19 at 12:20
  • 1
    As a workaround you can use actuator's endpoint [shutdown](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html) to trigger the graceful shutdown. – cdalxndr Oct 02 '19 at 12:47

0 Answers0