Graceful shutdown is supported by all four built-in web servers (Jetty, Reactor Netty, Tomcat, and Undertow), as well as reactive and servlet-based web applications. It occurs as part of closing the application context and is executed at the earliest stage of stopping the SmartLifecycle beans. This termination processing procedure uses a timeout that provides a grace period during which existing requests will be allowed to complete but new requests will not be submitted. The exact way to prevent new requests from being sent depends on the web server you are using. Jetty, Reactor Netty and Tomcat will stop accepting requests at the network level. Undertow will accept requests, but immediately return a "service unavailable" (503) response.

For a smooth shutdown when using Tomcat, Tomcat version 9.0.33 or later is required.

To enable shutdown mode, configure the server.shutdown property as shown in the following example:

Properties
server.shutdown=graceful
Yaml
server:
  shutdown: "graceful"

To configure the timeout period, configure the spring.lifecycle.timeout-per-shutdown-phase property, as shown in the following example:

Properties
spring.lifecycle.timeout-per-shutdown-phase=20s
Yaml
spring:
  lifecycle:
    timeout-per-shutdown-phase: "20s"
The graceful shutdown mode in your IDE may not work properly if it does not send the proper SIGTERM signal. For more information, see your IDE's documentation.