| | |
| | | package com.xiaopeng.pushMessage.webSocket.config; |
| | | |
| | | import com.xiaopeng.pushMessage.webSocket.handler.PushMessageWebSocketHandler; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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; |
| | | |
| | | /** |
| | | * Spring WebSocket 配置 |
| | | * 注册 /websocket 端点,共用 Spring Boot HTTP 端口 |
| | | */ |
| | | @Configuration |
| | | @EnableWebSocket |
| | | public class WebSocketConfig implements WebSocketConfigurer { |
| | | |
| | | @Autowired |
| | | private PushMessageWebSocketHandler pushMessageWebSocketHandler; |
| | | |
| | | @Override |
| | | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
| | | registry.addHandler(pushMessageWebSocketHandler, "/websocket") |
| | | // 允许所有跨域来源,生产环境可按需收紧 |
| | | .setAllowedOrigins("*"); |
| | | } |
| | | } |
| | | //package com.xiaopeng.pushMessage.webSocket.config; |
| | | // |
| | | //import com.xiaopeng.pushMessage.webSocket.handler.PushMessageWebSocketHandler; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | //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; |
| | | // |
| | | ///** |
| | | // * Spring WebSocket 配置 |
| | | // * 注册 /websocket 端点,共用 Spring Boot HTTP 端口 |
| | | // */ |
| | | //@Configuration |
| | | //@EnableWebSocket |
| | | //public class WebSocketConfig implements WebSocketConfigurer { |
| | | // |
| | | // @Autowired |
| | | // private PushMessageWebSocketHandler pushMessageWebSocketHandler; |
| | | // |
| | | // @Override |
| | | // public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { |
| | | // registry.addHandler(pushMessageWebSocketHandler, "/websocket") |
| | | // // 允许所有跨域来源,生产环境可按需收紧 |
| | | // .setAllowedOrigins("*"); |
| | | // } |
| | | //} |