WebSockets

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

Spring Boot provides WebSockets auto-configuration for embedded Tomcat, Jetty, and Undertow. If you deploy a war file to a standalone container, Spring Boot assumes that the container is responsible for the configuration of its WebSocket support.

Spring Framework 为可通过 spring-boot-starter-websocket 模块轻松访问的 MVC Web 应用程序提供 {url-spring-framework-docs}/web/websocket.html[丰富的 WebSocket 支持]。

Spring Framework provides {url-spring-framework-docs}/web/websocket.html[rich WebSocket support] for MVC web applications that can be easily accessed through the spring-boot-starter-websocket module.

WebSocket 支持也适用于 {url-spring-framework-docs}/web/webflux-websocket.html[响应式 Web 应用程序],并且需要在 spring-boot-starter-webflux 旁边包含 WebSocket API:

WebSocket support is also available for {url-spring-framework-docs}/web/webflux-websocket.html[reactive web applications] and requires to include the WebSocket API alongside spring-boot-starter-webflux:

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