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.
To enable shutdown mode, configure the server.shutdown
property as shown in the following example:
server.shutdown=graceful
server:
shutdown: "graceful"
To configure the timeout period, configure the spring.lifecycle.timeout-per-shutdown-phase
property, as
shown in the following example:
spring.lifecycle.timeout-per-shutdown-phase=20s
spring:
lifecycle:
timeout-per-shutdown-phase: "20s"
SIGTERM
signal. For more information, see your IDE's documentation.
GO TO FULL VERSION