How to shutdown Spring Boot applications gracefully

This article will teach you how to gracefully shut-down a Spring Boot application using the Actuator endpoints. We will also show how to configure a minimal security layer to protect access to this resource.

Configuring Spring Boot dependencies

Firstly, build a Spring Boot project which includes the following dependencies:

spring boot shutdown gracefully

Within the project, you will now find the following Spring Boot starters:


Configuring application properties

Next, we we need to enable the shutdown endpoint. We will also expose all available Actuator Endpoints:


Adding the Security Configuration Class

Finally, we need a Class to handle the Authentication.

import org.springframework.context.annotation.Configuration;
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {

    protected void configure(HttpSecurity http) throws Exception {

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {                


Testing application shutdown

With our Classes and Configuration in place, we can now test the shutdown of our Spring Boot application using the Actuator /shutdown endpoint.

mvn install spring-boot:run

Next, shutdown the application as follows:

$ curl -i -X POST http://localhost:8080/actuator/shutdown -u admin:password

{"message":"Shutting down, bye..."}


This article discussed how to gracefully shutdown a Spring Boot application using the Actuator and the Security Starter. You can find the application source code here:

Leave a comment