org.springframework.boot
spring-boot-starter-websocket
- 新建配置类:
package io.xcc.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
/**
-
注入ServerEndpointExporter,
-
这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint
*/
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
- 新建实现类:
@Component
@ServerEndpoint(“/ws/awdMatch/{userId}”)
public class AWDMatchWebSocket {
private Session session;
private static CopyOnWriteArraySet webSockets = new CopyOnWriteA