SpringBoot2.x系列教程(四十五)Spring Boot集成WebSocket实现技术交流群功能

在上篇文章中,我们了解了WebSocket的基本功能及相关概念。本篇文章中我们以具体的实例来演示,在Spring Boot中整合WebSocket,同时实现一个场景的业务场景功能。

针对在Spring Boot中使用合WebSocket通常有两种形式:直接基于WebSocket协议进行集成和基于STOMP协议进行集成。本篇文章我们基于WebSocket协议来完成相应功能。

业务场景

实例的基本业务场景如下:

在某官方网站上,提供用户匿名在线技术交流功能。用户点击网页,即可为用户生成一个匿名,用户可以看到当前在线人的昵称信息,随后可以在群里发送消息进行交流。

Spring Boot集成WebSocket

引入依赖文件:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

其中spring-boot-starter-websocket

猜你喜欢

转载自blog.csdn.net/wo541075754/article/details/104512976