主要代码是抄的别的博主,这里记一下原po缺少的内容,引路:
https://www.cnblogs.com/Createsequence/p/11335655.html
代码上基本照抄,不过我没有装过滤器什么的,注意对应一下访问路由
注册WebSocket的Bean
参照https://www.cnblogs.com/xuwenjin/p/12664650.html
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 new ServerEndpointExporter();
}
}
ServerEndpointExporter 无法引用
参照https://blog.csdn.net/qq_38086463/article/details/90518948 我按照上po做后可以了
<groupId>com.cakecn</groupId>
<artifactId>springboot_test06</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot_test06</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
总结构如图
|