通过https://start.spring.io/生成一个websocket项目。老项目则增加websocket的starter
其中websocket核心包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
将生成的项目导入ide后开始配置websocket
第一步,增加websocket配置,ServerEndpointExporter将我们配置的websocket接口地址发布出来,外面才可以调用
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return