# 10.7. WebSockets

Spring Boot 为嵌入式 Tomcat、Jetty 和 Undertow 提供 WebSockets 自动配置。如果将 war 文件部署到独立容器，Spring Boot 会假定该容器负责配置其 WebSocket 支持。

Spring框架为MVC Web应用程序提供了[丰富的WebSocket支持](https://docs.spring.io/spring-framework/reference/6.1/web/websocket.html)，可以通过`spring-boot-starter-websocket`模块轻松访问。

WebSocket 支持也可用于[反应式 Web 应用程序](https://docs.spring.io/spring-framework/reference/6.1/web/webflux-websocket.html)，并且需要同时包含属于`spring-boot-starter-webflux`的 WebSocket API ：

```
<dependency>
    <groupId>jakarta.websocket</groupId>
    <artifactId>jakarta.websocket-api</artifactId>
</dependency>
```


---

# 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/10.-xiao-xi/10.7.-websockets.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.
