Spring Boot Starter WebSocket 详细说明文档

spring-boot-starter-websocket创建服务 websocket 阅读详情

一、什么是 spring-boot-starter-websocket

spring-boot-starter-websocket 是 Spring Boot 提供的一个自动配置启动器(Starter),用于快速集成 WebSocket 协议支持。它封装了 Spring Framework 的 WebSocket 功能,包括 STOMP(Simple Text Oriented Messaging Protocol)消息协议支持,使得开发者可以轻松地在 Spring Boot 应用中实现双向实时通信。

核心依赖包含:

  • spring-websocket:WebSocket 协议核心支持
  • spring-messaging:消息抽象层,支持 STOMP
  • sockjs:兼容性库,用于在不支持 WebSocket 的浏览器中模拟 WebSocket(如降级为轮询)
  • stomp-websocket:STOMP 协议客户端/服务端实现

✅ 一句话总结:spring-boot-starter-websocket 让你只需几行配置,就能在 Spring Boot 应用中实现类似微信聊天、实时股票行情、在线协作编辑器、游戏实时状态同步等场景的双向通信功能。


二、WebSocket 与 STOMP 的区别

特性WebSocketSTOMP over WebSocket
协议层级原始二进制/文本协议应用层消息协议(基于 WebSocket)
消息格式自定义标准化格式(SEND, SUBSCRIBE, MESSAGE 等)
开发复杂度高(需自己设计协议)低(有标准命令和消息头)
适用场景高性能实时流(如游戏)企业级应用(聊天、通知、仪表盘)
Spring 支持基础支持完整封装(推荐)

💡 推荐使用 STOMP:在大多数业务系统中,STOMP 更易用、可维护、可扩展,Spring Boot 对其支持最完善。


三、主要功能与应用场景

功能描述实际应用场景
实时消息推送服务端主动向客户端推送消息股票行情、系统通知、订单状态更新
多用户聊天多个客户端之间互相发送消息在线客服、团队协作聊天
用户在线状态实时感知用户上线/下线社交应用、IM系统
实时数据监控实时展示设备/服务器指标监控大屏、IoT 数据看板
协同编辑多人同时编辑同一文档Google Docs 类型应用
游戏实时同步玩家动作同步、状态更新浏览器多人小游戏

四、完整开发示例:实时聊天室系统(含详细中文注释)

✅ 项目结构

src/
├── main/
│   ├── java/
│   │   └── com/example/websocketdemo/
│   │       ├── WebSocketDemoApplication.java        // 启动类
│   │       ├── config/WebSocketConfig.java          // WebSocket 配置
│   │       ├── controller/ChatController.java       // 消息控制器
│   │       └── service/ChatService.java             // 业务服务
│   └── resources/
│       └── static/
│           └── chat.html                            // 前端聊天页面

1. Maven 依赖(pom.xml)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>websocket-demo</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <!-- 引入 WebSocket 启动器,自动配置所有必要组件 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <!-- Web 依赖,提供 REST 接口和静态资源服务 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 可选:热部署开发工具 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <!-- 测试依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2. WebSocket 配置类(WebSocketConfig.java)

package com.example.websocketdemo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * WebSocket 消息代理配置类
 * 
 * 作用:配置 STOMP 消息代理、端点(Endpoint)、消息路由规则
 * 
 * @EnableWebSocketMessageBroker:启用 WebSocket 消息代理功能
 *   - 自动配置 SockJS、STOMP、消息代理(内存或外部如 Redis)
 *   - 启用 @MessageMapping 和 @SubscribeMapping 注解
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    /**
     * 注册 STOMP 端点(客户端连接入口)
     * 
     * 为什么需要端点?
     *   - 客户端通过此 URL 建立 WebSocket 连接(如:ws://localhost:8080/chat)
     *   - SockJS 会降级为 HTTP 长轮询,兼容老浏览器
     * 
     * withSockJS():启用 SockJS 兼容模式(推荐!)
     *   - 当浏览器不支持原生 WebSocket 时,自动降级为 AJAX 轮询
     *   - 保证在 IE9+、移动端等环境也能正常工作
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // 注册一个名为 "/chat" 的端点
        registry.addEndpoint("/chat")
                .setAllowedOriginPatterns("*")  // 允许所有来源(开发阶段使用,生产环境请限制)
                .withSockJS();                    // 启用 SockJS 兼容模式
    }

    /**
     * 配置消息代理(Message Broker)
     * 
     * 两种代理类型:
     *   1. 内存代理(simple):适用于单机应用,消息存储在 JVM 内存中
     *   2. 外部代理(如 Redis):适用于集群部署,消息跨节点同步
     * 
     * setApplicationDestinationPrefixes:指定客户端发送消息的前缀
     *   - 客户端发送消息时,必须以 "/app" 开头,如:/app/chat
     *   - Spring 会将这些消息路由到 @MessageMapping 注解的方法
     * 
     * setUserDestinationPrefix:指定用户私有消息前缀
     *   - 用于向特定用户发送消息,如:/user/{username}/queue/messages
     *   - 需要结合 @SendToUser 使用
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 配置客户端可订阅的主题前缀(广播/群组消息)
        // 客户端使用 subscribe("/topic/public") 订阅公共消息
        registry.enableSimpleBroker("/topic", "/queue");

        // 配置客户端发送消息的目标前缀
        // 客户端发送消息必须以 /app 开头,如:/app/chat
        // Spring 会将这些消息映射到 @MessageMapping("/chat") 的方法
        registry.setApplicationDestinationPrefixes("/app");

        // 配置用户私有消息前缀,用于一对一消息推送
        // 如:/user/张三/queue/messages
        registry.setUserDestinationPrefix("/user");
    }
}

3. 消息控制器(ChatController.java)

package com.example.websocketdemo.controller;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * STOMP 消息控制器
 * 
 * 作用:接收客户端通过 WebSocket 发送的消息,并广播或定向发送给其他客户端
 * 
 * @Controller:标记为 Spring 控制器,但不返回视图,只处理消息
 * @MessageMapping:映射客户端发送的消息路径(与 setApplicationDestinationPrefixes 配合)
 * @SendTo:将消息广播到指定主题(所有订阅者都能收到)
 * @SubscribeMapping:当客户端订阅某个主题时自动触发(用于初始化数据)
 */
@Controller
public class ChatController {

    /**
     * 接收客户端发送的聊天消息
     * 
     * 客户端发送路径:/app/chat
     * 此方法会自动接收所有发送到 /app/chat 的消息
     * 
     * @Payload:自动将消息体(JSON)绑定为 ChatMessage 对象
     * @SendTo("/topic/public"):将消息广播到 /topic/public 主题
     *   - 所有订阅了 /topic/public 的客户端都会收到这条消息
     * 
     * 注意:消息体必须是 JSON 格式,Spring 自动反序列化为 Java 对象
     */
    @MessageMapping("/chat")
    @SendTo("/topic/public")
    public ChatMessage sendMessage(@Payload ChatMessage message) {
        // 为消息添加时间戳,便于前端展示
        message.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        return message; // 自动序列化为 JSON 并广播到 /topic/public
    }

    /**
     * 处理用户登录事件(可选)
     * 
     * 当客户端首次连接并订阅 /user/{username}/queue/messages 时触发
     * 可用于发送欢迎消息、在线状态更新等
     */
    @MessageMapping("/user.login")
    @SendToUser("/queue/notifications")
    public ChatMessage handleUserLogin(@Payload ChatMessage message, SimpMessageHeaderAccessor headerAccessor) {
        String username = message.getFrom(); // 从消息中获取用户名
        ChatMessage response = new ChatMessage();
        response.setFrom("系统");
        response.setContent(username + " 已上线!");
        response.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        return response;
    }

    /**
     * 当客户端订阅 /app/hello 时,自动返回欢迎信息
     * 
     * 与 @MessageMapping 不同:
     *   - @MessageMapping:客户端主动发送消息触发
     *   - @SubscribeMapping:客户端订阅主题时自动触发(无需客户端主动发消息)
     * 
     * 适用于:首次连接时返回欢迎语、初始化数据、在线人数统计等
     */
    @SubscribeMapping("/app/hello")
    public ChatMessage handleHello() {
        ChatMessage message = new ChatMessage();
        message.setFrom("系统");
        message.setContent("欢迎使用 WebSocket 聊天室!");
        message.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        return message;
    }
}

4. 消息实体类(ChatMessage.java)

package com.example.websocketdemo.controller;

import java.time.LocalDateTime;

/**
 * 聊天消息实体类
 * 
 * 作用:定义客户端与服务端之间传输的消息结构
 * 
 * 注意:
 *   - 必须是 POJO(普通 Java 对象)
 *   - 字段名必须与前端 JSON 字段名一致(默认是 camelCase)
 *   - Spring 会自动将 JSON 反序列化为此对象
 *   - 也可以使用 @JsonProperty 注解指定字段映射
 */
public class ChatMessage {

    private String from;      // 发送者用户名
    private String content;   // 消息内容
    private String timestamp; // 发送时间(字符串格式)

    // 无参构造函数(Jackson 反序列化必需)
    public ChatMessage() {}

    // 全参构造函数(方便测试)
    public ChatMessage(String from, String content, String timestamp) {
        this.from = from;
        this.content = content;
        this.timestamp = timestamp;
    }

    // Getter 和 Setter 方法(必须提供,用于序列化/反序列化)
    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }
}

5. 前端聊天页面(resources/static/chat.html)

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>WebSocket 聊天室</title>
    <script src="https://cdn.jsdelivr.net/npm/sockjs-client@1.6.1/dist/sockjs.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/stompjs@2.3.3/lib/stomp.min.js"></script>
    <style>
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 20px; }
        #chat-box { width: 600px; height: 400px; border: 1px solid #ccc; padding: 10px; overflow-y: auto; margin-bottom: 10px; }
        #message-input { width: 400px; padding: 8px; }
        #send-btn { padding: 8px 16px; }
        .system { color: #888; font-style: italic; }
        .me { background-color: #e3f2fd; padding: 5px 10px; border-radius: 10px; margin: 5px 0; }
        .other { background-color: #f0f0f0; padding: 5px 10px; border-radius: 10px; margin: 5px 0; }
    </style>
</head>
<body>
    <h2>🚀 WebSocket 实时聊天室</h2>
    <div id="chat-box"></div>
    <input type="text" id="message-input" placeholder="输入消息..." />
    <button id="send-btn">发送</button>
    <button id="connect-btn">连接</button>
    <button id="disconnect-btn">断开</button>

    <script>
        // ---------------------- 初始化变量 ----------------------
        let stompClient = null; // STOMP 客户端实例
        let username = null;    // 当前用户昵称

        // ---------------------- 连接 WebSocket ----------------------
        function connect() {
            // 创建 SockJS 连接(兼容性好,自动降级)
            // 服务端注册的端点是 /chat
            const socket = new SockJS('http://localhost:8080/chat');

            // 创建 STOMP 客户端
            stompClient = Stomp.over(socket);

            // 连接到服务器
            stompClient.connect({}, function (frame) {
                console.log('✅ 已连接到 WebSocket 服务器:', frame);

                // 1. 订阅公共聊天主题(接收所有人的消息)
                //   - 服务端广播到 /topic/public,客户端订阅此主题接收
                stompClient.subscribe('/topic/public', function (message) {
                    displayMessage(JSON.parse(message.body));
                });

                // 2. 订阅用户私有消息(用于接收系统通知)
                //   - 服务端使用 @SendToUser 发送,路径为 /user/{username}/queue/messages
                stompClient.subscribe('/user/queue/notifications', function (message) {
                    displayMessage(JSON.parse(message.body), 'system');
                });

                // 3. 订阅欢迎消息(测试 @SubscribeMapping)
                stompClient.subscribe('/app/hello', function (message) {
                    displayMessage(JSON.parse(message.body), 'system');
                });

                // 4. 设置当前用户名(模拟登录)
                username = prompt("请输入您的昵称:") || "游客" + Math.floor(Math.random() * 100);
                document.getElementById('message-input').placeholder = '你好,' + username + ',输入消息...';

                // 5. 向服务端发送登录消息(可选)
                stompClient.send("/app/user.login", {}, JSON.stringify({from: username}));
            }, function (error) {
                console.error('❌ 连接失败:', error);
                alert('连接失败,请检查服务端是否启动!');
            });
        }

        // ---------------------- 发送消息 ----------------------
        function sendMessage() {
            const input = document.getElementById('message-input');
            const message = input.value.trim();

            if (message && stompClient && stompClient.connected) {
                // 发送消息到服务端 /app/chat 路径
                // 服务端 @MessageMapping("/chat") 会接收此消息
                stompClient.send("/app/chat", {}, JSON.stringify({
                    from: username,     // 发送者
                    content: message, // 消息内容
                    timestamp: ""     // 时间由服务端生成
                }));

                // 清空输入框
                input.value = '';
            } else {
                alert('请先连接服务器!');
            }
        }

        // ---------------------- 显示消息到页面 ----------------------
        function displayMessage(message, type = 'other') {
            const chatBox = document.getElementById('chat-box');
            const msgDiv = document.createElement('div');

            // 根据类型设置样式
            if (type === 'system') {
                msgDiv.className = 'system';
                msgDiv.textContent = `[${message.timestamp}] ${message.from}: ${message.content}`;
            } else if (message.from === username) {
                msgDiv.className = 'me';
                msgDiv.textContent = `${message.from} (${message.timestamp}): ${message.content}`;
            } else {
                msgDiv.className = 'other';
                msgDiv.textContent = `${message.from} (${message.timestamp}): ${message.content}`;
            }

            chatBox.appendChild(msgDiv);
            chatBox.scrollTop = chatBox.scrollHeight; // 自动滚动到底部
        }

        // ---------------------- 绑定事件 ----------------------
        document.getElementById('send-btn').addEventListener('click', sendMessage);
        document.getElementById('message-input').addEventListener('keypress', function (e) {
            if (e.key === 'Enter') {
                sendMessage();
            }
        });

        document.getElementById('connect-btn').addEventListener('click', connect);
        document.getElementById('disconnect-btn').addEventListener('click', function () {
            if (stompClient && stompClient.connected) {
                stompClient.disconnect();
                console.log('👋 已断开连接');
                alert('已断开连接');
            }
        });

        // 页面加载完成后自动尝试连接
        window.onload = function () {
            connect();
        };
    </script>
</body>
</html>

6. 启动类(WebSocketDemoApplication.java)

package com.example.websocketdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Spring Boot 启动类
 * 
 * 作用:启动整个 Spring Boot 应用
 * 
 * @SpringBootApplication:组合注解,包含:
 *   - @Configuration:标记为配置类
 *   - @EnableAutoConfiguration:启用自动配置
 *   - @ComponentScan:扫描包下所有组件(Controller、Service、Config 等)
 */
@SpringBootApplication
public class WebSocketDemoApplication {
    public static void main(String[] args) {
        // 启动 Spring Boot 应用
        SpringApplication.run(WebSocketDemoApplication.class, args);
        System.out.println("🎉 WebSocket 聊天室服务已启动,请访问:http://localhost:8080/chat.html");
    }
}

五、运行与测试

✅ 启动步骤:

  1. 启动服务端:

    mvn spring-boot:run
    

    控制台输出:

    🎉 WebSocket 聊天室服务已启动,请访问:http://localhost:8080/chat.html
    
  2. 打开浏览器:

    • 访问 http://localhost:8080/chat.html
    • 输入昵称(如:张三)
    • 打开另一个浏览器标签页(或使用隐身模式),输入另一个昵称(如:李四)
  3. 测试效果:

    • 张三发送消息 → 李四立即收到
    • 李四回复 → 张三立即收到
    • 系统自动发送欢迎语
    • 断开重连 → 重新连接后仍可接收消息

六、进阶优化建议

优化方向说明
用户认证结合 Spring Security,在连接时验证 Token,绑定用户身份
集群部署使用 Redis 作为 STOMP 消息代理(替换 enableSimpleBroker → enableStompBrokerRelay)
心跳检测配置 heartbeat 避免连接被防火墙断开
消息持久化将聊天记录存入数据库,支持历史消息查询
消息限流防止刷屏,使用 @RateLimit 或 SimpMessagingTemplate 限流
前端框架集成可与 Vue/React/Angular 集成,使用 vue-stomp、ngx-stomp 等库

七、常见问题与解决方案

问题原因解决方案
Connection refused服务未启动或端口被占用检查控制台日志,确认端口 8080 是否被占用
Cannot connect to WebSocket endpoint前端地址错误确保 new SockJS('http://localhost:8080/chat') 与服务端 addEndpoint("/chat") 一致
404 Not Found静态资源未加载确保 chat.html 放在 src/main/resources/static/ 目录下
消息收不到订阅路径错误检查 subscribe('/topic/public') 是否与 @SendTo("/topic/public") 完全一致
跨域问题浏览器报错在 registerStompEndpoints 中添加 .setAllowedOriginPatterns("*")

八、总结

维度说明
核心价值实现低延迟、双向、实时通信,替代轮询和长轮询
技术优势基于 Spring 生态,开发效率高,兼容性好,文档丰富
适用场景聊天、通知、监控、协同编辑、实时数据推送
推荐架构Spring Boot + STOMP + SockJS + HTML5
生产建议集群部署时使用 Redis 作为消息代理,配合 Spring Security 做权限控制

✅ 最佳实践:优先使用 @MessageMapping + @SendTo + SockJS 模式,避免直接使用原始 WebSocket,降低开发复杂度。


附录:完整项目 GitHub 模板(可直接克隆)

git clone https://github.com/example/spring-boot-websocket-chat-demo.git
cd spring-boot-websocket-chat-demo
mvn spring-boot:run

📌 本示例已通过 Spring Boot 3.2 + Java 17 测试,可直接用于生产项目参考。


💡 结语:spring-boot-starter-websocket 是实现现代 Web 实时交互的“瑞士军刀”。掌握它,你就能轻松构建微信、钉钉、飞书、股票行情、在线游戏等主流应用的实时通信功能!

Spring Boot Starter WebSocket 是一个用于简化在 Spring Boot 应用中集成 WebSocket 功能的 starter 通过使用 Spring Boot Starter WebSocket,开发者可以快速地创建一个支持 WebSocket 的 Spring Boot 应用,而不需要手动配置大量的代码。使用 Spring Boot Starter WebSocket,开发者可以轻松地创建 WebSocket 服务端和客户端,实现实时的双向通信。HTML5的诞生,WebSocket协议被提出,它实现了浏览器与服务器的全双工通信,扩展了浏览器与服务端的通信功能,使服务端也能主动向客户端发送数据。,发送消息并接收响应。 阅读详情

相关推荐

Spring Boot 使用 WebSocket 实现消息推送 及 WebSocket原理

WebSocket 是什么原理,为什么可以实现持久连接? 一、WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算) 首先HTTP有1.1和1.0之说,也就是所谓的keep-alive,把多个HTTP请求合并为一个,但是Websocket其实是一个新协议,跟HTTP协议基本没有关系,只是为了兼容

二一点 1万+

十一、Spring Boot 整合 WebSocket(2)

Spring Boot 整合 WebSocket

走在bug的路上 3891

Spring Boot整合WebSocket

WebSocket 是一种在单个 TCP 连接上进行全双工通信的协议。它允许客户端和服务器之间进行实时数据交换,而无需每次都重新建立连接。WebSocket 的核心特性包括:双向通信:客户端和服务器都可以主动发送和接收消息。低延迟:由于 WebSocket 连接是持久的,消息可以立即传递,而不需要重复的 HTTP 请求。节省资源:通过减少 HTTP 请求的开销,WebSocket 可以节省带宽和服务器资源。

web15085096641的博客 1465

SpringBoot整合WebSocket详细教程

springboot整合websocket

lianaozhe的博客 2861

spring boot websocket 的使用

/如果spingboot配置文件中中配置了server.servlet.context-path,则格式为ws//ip接口启动的端口/server.servlet.context-path的名称/webSocketDemo。//连接到WebSocket的url地址。格式为ws//ip接口启动的端口/webSocketDemo。//连接发生错误的回调方法。//连接成功建立的回调方法。//ws连接断开的回调方法。//接收到消息的回调方法。//将消息显示在网页上。...

张小三的博客 3069

websocket系列:基于spring-boot-starter-websocket实现

基于spring-boot-starter-websocket实现websocket

弹指天下 3万+

快速构建WebSocket服务的利器:websocket-spring-boot-starter

快速构建WebSocket服务的利器:websocket-spring-boot-starter 在现代Web应用中,实时通信变得越来越重要。WebSocket作为一种高效的实时通信协议,被广泛应用于各种场景。然而,传统的WebSocket开发往往需要大量的配置和代码,这无疑增加了开发的复杂性。为了解决这一问题,websocket-spring-boot-starter应运而生,它提供了一种简单、...

gitblog_00958的博客 1307

SpringBoot整合配置WebSocket服务代码实现

WebSocket是一种在单个TCP连接上进行全双工通信的网络协议,它可以在客户端和服务器之间建立持久性的连接,并提供实时的双向通信能力。相较于传统的HTTP协议,WebSocket具有更低的延迟和更高的效率,适用于需要实时数据传输和实时互动的应用场景。

洛阳泰山的博客 4105

websocket系列基于spring-boot-starter-websocket实现

本篇主要是介绍怎么基于spring-boot-starter-websocket来实现websocket。

jiaowoshangege的博客 1556

websocket系列:基于netty-websocket-spring-boot-starter轻松实现高性能websocket

基于netty-websocket-spring-boot-starter轻松实现高性能websocket

弹指天下 1万+

websocket系列:基于tio-websocket-spring-boot-starter实现

websocket系列:基于tio-websocket-spring-boot-starter实现

弹指天下 4635

WebSocket Spring Boot Starter 项目教程

WebSocket Spring Boot Starter 项目教程 1. 项目目录结构及介绍 websocket-spring-boot-starter ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ └── lazyboyl │ │ │ ├── config │ ...

gitblog_00550的博客 521

计量经济学——事件研究法/事件分析法

计量经济学——事件研究法/事件分析法

weixin_46189461的博客 6752

WebSocket | Netty netty-websocket-spring-boot-starter

本文讲述 基于springboot + netty 实现websocket服务端搭建。 使用springboot 集成 netty-websocket-spring-boot-starter 来实现websocket

苏老师的博客 2326

Sharding-JDBC 系列专题 - 第九篇:高可用性与集群管理

高可用性是指系统在面对故障(如数据库宕机、网络中断)时,能够快速恢复并继续提供服务。Sharding-JDBC 和 Sharding-Proxy 提供了多种机制支持高可用性,同时需要结合底层数据库的高可用方案(如 MySQL 主从复制、MHA)来实现。高可用性和集群管理是 Sharding-JDBC 和 Sharding-Proxy 在生产环境中成功应用的关键。本篇详细介绍了数据库高可用方案、Sharding-JDBC 的故障切换机制、Sharding-Proxy 的集群部署,以及分布式治理功能。

资深架构师分享:深入剖析软件架构,探讨云计算、微服务、大数据等前沿技术。分享实践经验,促进技术交流,共同构建卓越系统。 1392

葵花 Himawari 8/9号数据学习记录-01-数据初识

葵花卫星学习记录,第一章:卫星的来源与卫星数据的波段介绍

weixin_44111909的博客 532

Spring Boot整合websocket遇到的小问题

在项目根目录下创建一个endpoint包,在endpoint包下创建一个WebSocket类,在类上添加@Component和@ServerEndpoint注解,并通过@ServerEndpoint的value属性指定请求路径,用法类似于@RequestMapping。意思是onOpen()方法上的一个String类型的参数上没有用@PathParam注解,检查了一下,确实没有用这个注解,用的是@PathVariable,这两个注解的作用是类似的,都是获取rest风格请求的参数。修改之后能正常启动了。

沐雨橙风ιε的博客 3772

MIMIC-IV数据库中患者院内死亡的单因素生存分析

目的 由易到难,对mimic-iv的查询进行实际操作,体现先前文章中提到的mimic-iv数据查询的规律。 数据分析计划 死亡,是重症患者最重要的结局指标,在MIMIC数据库中收录了院内死亡的数据,以及进出ICU的时间(和进出医院的时间),所以我们可以获得是否死亡,以及从入ICU(或入院)到死亡发生之间的时间,有了这两个指标,我们可以通过Cox单因素(参数和非参数)模型来观察ICU(和医院)内死亡的趋势,以及某个变量(比如,性别和种族等)对死亡趋势的影响,以为后续的分析奠定基础。 数据的获取 我们需要数个变

skyskytotop的博客 3184

tio-websocket-spring-boot-starter 的简单使用

引言T-io网络通讯框架开源之后受到许多同学的喜欢,但是对于使用Spring系列技术的同学用起来稍许不适。于是乎抽时间写了个 starter,很荣幸代码被作者采纳,正式入驻T-io家族包。 tio-websocket-servertio-websocket-server 是基于tio的websocket协议的实现。并且,无缝对接点对点发送消息,群组消息,客户端连接维护等。所以,基于 t...

weixin_30471065的博客 4631

【AI智能体】Codex AI 辅助编程高级技能实战操作详解

Codex AI 辅助编程高级技能实战操作详解

congge 6755

Python 爬虫实战:爬取哔哩哔哩知识区,抓取高赞课程信息

哔哩哔哩(Bilibili)是一个广受欢迎的综合性视频社区,其中的知识区汇聚了大量优质的教育、科普、技术等课程内容。本文将指导读者如何使用 Python 爬虫技术从哔哩哔哩知识区抓取高赞课程信息,并进行数据分析。本文深入探究了利用 Python 爬虫技术从哔哩哔哩知识区抓取高赞课程信息的全流程。从前期的环境搭建、模拟登录,到核心的课程数据抓取、存储,再到后续的数据分析与可视化,都详细展开讲解并提供代码支持。通过此方法所获取的数据,能够助力创作者优化内容、用户发现优质课程、平台洞察用户需求。

u014481728的博客 1133

netty-websocket-spring-boot-starter基于netty的轻量级的高性能socket服务器

netty 老生常谈,干啥的?一个网络通信协议框架,自己可以各种自定义,具体的,网上一捞一大把。两大特性:NIO和零拷贝。 netty-websocket-spring-boot-starter 版本约定:0.9.5 基于此版演绎的,因为每个版本有轻微区别 官方文档: 直达网站https://gitee.com/Yeauty/netty-websocket-spring-boot-starter 这是个开源的框架。通过它,我们可以像spring-boot-starter-websocket一样使用注解进行开

NICVSY的博客 7844

16、AI与无人机助力紧急器官移植及医疗物资运输

本文探讨了AI与无人机(UAV)集成模型在紧急器官移植和医疗物资运输中的应用。传统运输方式受限于交通、时间和环境因素,而基于图神经网络(GNN)的AI-UAV系统可实现高效、智能、全天候的医疗物资配送,具备实时温湿度监控、自动导航和适应复杂地形等优势。文章分析了该模型在血液、器官运输中的关键作用,展示了其在澳大利亚、中国、美国等国的实际应用案例,并通过表格与流程图说明运作机制。同时,文章还探讨了技术、法规和社会层面的挑战及应对策略,展望了未来技术融合、应用拓展和国际合作的发展趋势,凸显其在全球医疗物流中的广

lll78的博客 102

【SpringBoot框架篇】8.搭建自己的spring-boot-starter

文章目录简述创建starter服务引入构建starter的核心依赖创建配置类封装服务提供者注册Bean对象暴露需要被装配的类发布jar包到本地仓库引入我的my-spring-boot-starter依赖引入依赖修改配置文件启动程序 简述 我们可以认为starter是一种服务,在使用某个功能的开发者不需要关注各种依赖库的处理,不需要具体的配置信息,由Spring Boot自动注入的bean。 我们在开发springboot项目的时候,经常会引用spring-boot-starter-web,spring-bo

皓亮君的博客 3785

华为 MetaERP 财务模块的核心业务对象,按子模块与架构维度分类,以表格呈现,适配架构设计与实施落地

华为MetaERP财务模块基于4A架构(业务/应用/数据/技术)与TOGAF框架,实现业财一体化与全球合规。业务架构涵盖组织模型与核心流程,应用架构支撑财务操作,数据架构确保数据一致性,技术架构提供高性能技术底座。模块覆盖总账、应收应付、资产等子模块,支持多组织、多币种、多准则核算,通过实时会计引擎实现"交易即核算"。4A架构与TOGAF框架对应,实现业务能力、应用组件、数据模型与技术栈的深度融合,为华为全球化财务核算提供核心支撑。

金牌架构师 434

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

上一篇: 核保模块详细技术文档
下一篇: WebSocket 详细技术文档:原理、作用、特点与 HTTP 对比
龙茶清欢
博客等级 码龄7年 3720粉丝 375原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

龙茶清欢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值