这里仅仅是为了模拟一个websocket服务端用于测试客户端的断连重连,重点是websocket的连接,所以内容就比较随意了,仅仅返回一个累加的整数。
1、引入spring boot的websocket包(版本号随spring boot自动引入,实际上这里是5.2.5):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
2、最简化的配置类,一个端点,一个启动bean:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.con