基于Javax的实现
首先,在springboot 项目中的pom文件引入WebSocket的依赖,配置如下:
<!--websocket-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-tomcat</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
在springboot 项目中,新建WebSocketConfig配置类,代码如下:
import lombok.exter