12345678910111213141516171819202122232425262728293031323334 |
- package com.miniframe.websocket;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.socket.WebSocketHandler;
- import org.springframework.web.socket.config.annotation.EnableWebSocket;
- import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
- import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
- /**
- *
- * @author Goma
- *
- */
- @Configuration
- @EnableWebSocket
- public class WebSocketConfig implements WebSocketConfigurer {
-
- @Override
- public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
- registry.addHandler(myhandler(), "/websocket").addInterceptors(myInterceptors()).setAllowedOrigins("*");
- registry.addHandler(myhandler(), "/sockjs/websocket").addInterceptors(myInterceptors()).withSockJS();
- }
-
- @Bean
- public WebSocketHandler myhandler() {
- return new WebsocketEndPoint();
- }
-
- @Bean
- public HandShakeInterceptor myInterceptors() {
- return new HandShakeInterceptor();
- }
- }
|