整体功能说明
前后台可以对webSocket连接进行数据变更的传播。支持心跳和重连
ws1:
ws2:
1.创建项目
2.新建web目录
新建web目录存放前端静态文件
3.注入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.3.1.RELEASE</version> </dependency> <!--websocket连接需要使用到的包--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> <version>2.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.3.1.RELEASE</version> <scope>test</scope> </dependency>
静态文件打包(红字)
<build> <resources> <resource> <directory>src/main/web</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>