I can run a Spring Boot application with a following Maven command:
mvn spring-boot:run
but I don't know how to do a graceful shutdown of application which was started in a such way. Please advise.
In the Spring Boot Document, they said that 'Each SpringApplication will register a shutdown hook with the JVM to ensure that the ApplicationContext is closed gracefully on exit. ' When I click ctrl+c on the shell command, the application can be shutdown gracefully.
Close ApplicationContext Another option to shutdown Spring Boot application is to close Spring ApplicationContext using SpringApplication . SpringApplication#run(String…) method returns ApplicationContext as a < ConfigurableApplicationContext. We can use close() method to close ApplicationContext programmatically.
We know that a Spring Boot web app needs an embedded servlet container on the classpath. The app will shut down if it doesn't find any of the embedded servlet containers. To resolve the unexpected shut down during startup, we need to obtain a fully configured instance using the appropriate Starter.
To gracefully exit your application simply hit ctrl-c
in your terminal.
Or you can use mvn spring-boot:start
to start you app in background and mvn spring-boot:stop
to shutdown gracefuly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With