前几篇已经将项目转换成springboot了。发现还有websocket忘记配置了,现在简单配置一下保证可以使用先。
1、首先引入websocket的依赖
<!-- websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
2、开启ServerEndpoint注解
定义bean配置类
package com.boot.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @Author huangsan
* @create 2019/8/13 15:57
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter ServerEndpointExporter() {
return new ServerEndpointExporter();
}
}
3、在之前的@ServerEndpoint注释的websocket类上增加@Component注解交给springboot管理。
4、其他代码不需要更改即可继续正常使用websocket了。