Skip to content

Commit 0784c33

Browse files
committed
Updating the process of configuring WebSocket in Spring Boot.
1 parent 14bd566 commit 0784c33

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/system-design/web-real-time-message-push.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,22 @@ public class WebSocketServer {
374374
}
375375
```
376376

377+
服务端还需要注入`ServerEndpointerExporter`,这个 Bean 就会自动注册使用了`@ServerEndpoint`注解的 WebSocket 服务器。
378+
379+
```java
380+
@Configuration
381+
public class WebSocketConfiguration {
382+
383+
/**
384+
* 用于注册使用了 @ServerEndpoint 注解的 WebSocket 服务器
385+
*/
386+
@Bean
387+
public ServerEndpointExporter serverEndpointExporter() {
388+
return new ServerEndpointExporter();
389+
}
390+
}
391+
```
392+
377393
前端初始化打开 WebSocket 连接,并监听连接状态,接收服务端数据或向服务端发送数据。
378394

379395
```javascript

0 commit comments

Comments
 (0)