# 8.3. 优雅关机

所有四种嵌入式 Web 服务器（Jetty、Reactor Netty、Tomcat 和 Undertow）以及反应式和基于 servlet 的 Web 应用程序均支持正常关闭。`SmartLifecycle`它作为关闭应用程序上下文的一部分发生，并在停止Bean的最早阶段执行。此停止处理使用超时，该超时提供宽限期，在此期间将允许完成现有请求，但不允许新请求。不允许新请求的具体方式取决于所使用的 Web 服务器。Jetty、Reactor Netty和Tomcat将停止接受网络层请求。Undertow 将接受请求，但立即响应服务不可用 (503)。

> 使用 Tomcat 正常关闭需要 Tomcat 9.0.33 或更高版本。

要启用正常关闭，请配置`server.shutdown`属性，如以下示例所示：

```
server.shutdown=graceful
```

要配置超时时间，请配置`spring.lifecycle.timeout-per-shutdown-phase`属性，如下例所示：

```
spring.lifecycle.timeout-per-shutdown-phase=20s
```

如果 IDE 未发送正确的`SIGTERM`信号，则使用正常关闭可能无法正常工作。有关更多详细信息，请参阅 IDE 的文档。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.shiker.tech/spring-boot-can-kao-wen-dang/8.-wang-luo/8.3.-you-ya-guan-ji.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
