springboot配置websocket

2017-09-07  本文已影响86人  请你吃糖

参考文章:
http://blog.csdn.net/pacosonswjtu/article/details/51914567
http://blog.csdn.net/valenon/article/details/45892377
在这篇文章找到想要的(握手的时候传参数)
http://lippeng.iteye.com/blog/2299509

maven依赖

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
</dependency>

配置WebSocketConfig

@Configuration  
@EnableWebSocket  
public class WebSocketConfig implements WebSocketConfigurer{  
 @Override  
 public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {  
  registry.addHandler(getTextHandler(), "/websocket/");  
 } // 将 ChatTextHandler 处理器 映射到  /websocket/路径下.  
   
 @Bean  
 public ChatTextHandler getTextHandler() {  
  return new ChatTextHandler();  
 }  
} 
上一篇 下一篇

猜你喜欢

热点阅读