Backend Development 10 min read

Graceful Shutdown Support in Spring Boot 2.3+ for Embedded Web Servers

Since Spring Boot 2.3.0.RELEASE, graceful shutdown is supported for all embedded web servers (Jetty, Reactor Netty, Tomcat, Undertow) and both reactive and servlet‑based applications, using SmartLifecycle beans, configurable timeouts, and a JVM shutdown hook to allow in‑flight requests to finish while refusing new ones.

政采云技术
政采云技术
政采云技术
Graceful Shutdown Support in Spring Boot 2.3+ for Embedded Web Servers

Since Spring Boot 2.3.0.RELEASE, graceful shutdown is supported for all four embedded web servers (Jetty, Reactor Netty, Tomcat, Undertow) and for both reactive and servlet‑based web applications. The shutdown occurs as part of closing the application context and is performed by the earliest SmartLifecycle beans.

The mechanism works by registering a JVM shutdown hook that invokes doClose() on the application context. During doClose() , the DefaultLifecycleProcessor stops all beans implementing Lifecycle , ordering them by their Phase value (higher phase first). SmartLifecycle beans receive a callback and may perform asynchronous shutdown within a configurable timeout.

Spring Boot creates a bean that implements SmartLifecycle for the web server. For example, WebServerGracefulShutdownLifecycle registers the embedded server and calls webServer.shutDownGracefully(...) . In Tomcat, the TomcatWebServer uses a GracefulShutdown object when the shutdown property is set to GRACEFUL .

Configuration is done in application.yml (or properties) by setting:

server:
  shutdown: graceful
spring:
  lifecycle:
    timeout-per-shutdown-phase: 30s

The shutdown hook is registered automatically by Spring Boot; it can also be triggered via Actuator, which is outside the scope of this article.

In summary, Spring Boot’s graceful shutdown relies on the JVM shutdown hook, the SmartLifecycle infrastructure, and a per‑phase timeout mechanism to allow in‑flight requests to finish while refusing new ones, with specific behavior varying per embedded server.

BackendJavaSpringBootEmbeddedWebServerGracefulShutdownSmartLifecycle
政采云技术
Written by

政采云技术

ZCY Technology Team (Zero), based in Hangzhou, is a growth-oriented team passionate about technology and craftsmanship. With around 500 members, we are building comprehensive engineering, project management, and talent development systems. We are committed to innovation and creating a cloud service ecosystem for government and enterprise procurement. We look forward to your joining us.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.