2022-02-11 02:57:11 +08:00
|
|
|
package com.pj.ws;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
|
|
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
|
|
|
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WebSocket 相关配置
|
|
|
|
*
|
2023-05-08 13:47:59 +08:00
|
|
|
* @author click33
|
2022-05-01 13:34:46 +08:00
|
|
|
* @since: 2022-2-11
|
2022-02-11 02:57:11 +08:00
|
|
|
*/
|
|
|
|
@Configuration
|
|
|
|
@EnableWebSocket
|
|
|
|
public class WebSocketConfig implements WebSocketConfigurer {
|
|
|
|
|
|
|
|
// 注册 WebSocket 处理器
|
|
|
|
@Override
|
|
|
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
|
|
|
|
webSocketHandlerRegistry
|
|
|
|
// WebSocket 连接处理器
|
|
|
|
.addHandler(new MyWebSocketHandler(), "/ws-connect")
|
|
|
|
// WebSocket 拦截器
|
|
|
|
.addInterceptors(new WebSocketInterceptor())
|
|
|
|
// 允许跨域
|
|
|
|
.setAllowedOrigins("*");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|