I need to gracefully start and shutdown the spring boot application using a script . Is there any other way to do it except using an actuator module in the application. Currently i have to stop the spring boot process manually in the task manager.
Asked
Active
Viewed 8,551 times
3
-
do you want to handle the stop of the application or should the application stop after finishing the code? – Patrick Feb 26 '16 at 07:50
-
1Possible duplicate of [How to gracefully shutdown embeded jetty](http://stackoverflow.com/questions/30347144/how-to-gracefully-shutdown-embeded-jetty) – Serge Ballesta Feb 26 '16 at 08:11
-
How do you start your app exactly? – Stephane Nicoll Feb 26 '16 at 09:10
-
1Possible duplicate of [How to shutdown a Spring Boot Application in a correct way?](http://stackoverflow.com/questions/26547532/how-to-shutdown-a-spring-boot-application-in-a-correct-way) – Stewart Mar 15 '17 at 19:09
-
try this for graceful starting and stopping of the applications via shell script and pid file: https://stackoverflow.com/questions/26547532/how-to-shutdown-a-spring-boot-application-in-a-correct-way/51426095#51426095 – Anand Varkey Philips Jul 19 '18 at 15:20
1 Answers
2
Ultimately the spring boot application spins off a java process which needs to be killed. At present you are killing it manually.
You have a few options:
- You can use
SpringApplication.exit(ApplicationContext, ExitCodeGenerator...)
method. - If your application is not a long running application then do you have some exit point where your application should stop. At that point you can
System.exit(0)
- You can use external manager tools, for example on unix you can use supervisor, here is a blog you can read about this.
SpringApplication.run
gives youApplicationContext
which you can close.

Sandeep B
- 765
- 1
- 6
- 19
-
try this for graceful starting and stopping of the applications via shell script and pid file: https://stackoverflow.com/questions/26547532/how-to-shutdown-a-spring-boot-application-in-a-correct-way/51426095#51426095 – Anand Varkey Philips Jul 19 '18 at 15:18