简体   繁体   中英

How to gracefully shutdown the spring boot application

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.

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:

  1. You can use SpringApplication.exit(ApplicationContext, ExitCodeGenerator...) method.
  2. 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)
  3. You can use external manager tools, for example on unix you can use supervisor , here is a blog you can read about this.
  4. SpringApplication.run gives you ApplicationContext which you can close.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM