Anu Raman
Anu Raman

Reputation: 53

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.

Upvotes: 3

Views: 10136

Answers (1)

Sandeep B
Sandeep B

Reputation: 775

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.

Upvotes: 2

Related Questions