websocket配置

This commit is contained in:
wzy-warehouse
2026-05-18 10:17:02 +08:00
parent d2fc460c35
commit 2fe0db36df
3 changed files with 32 additions and 0 deletions
@@ -0,0 +1,28 @@
package com.gis.xian.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;
@Configuration
@EnableWebSocketMessageBroker // 启用WebSocket消息代理
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
// 启用简单的内存消息代理,客户端订阅以 "/topic" 开头的目的地
registry.enableSimpleBroker("/topic");
// 设置客户端发送消息的前缀,即 "/app"
registry.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
// 注册端点 "/websocket",客户端将通过此路径建立连接
registry.addEndpoint("/websocket")
.setAllowedOriginPatterns("*") // 允许所有源,支持携带凭证
.withSockJS();
}
}
+2
View File
@@ -42,11 +42,13 @@ safety:
- /crypto/sm2/public-key - /crypto/sm2/public-key
- /druid - /druid
- /algorithm-api/rainfall/grid - /algorithm-api/rainfall/grid
- /websocket/**
# 请求无需解密的路径 # 请求无需解密的路径
no-decrypt-paths: no-decrypt-paths:
- /crypto/sm2/public-key - /crypto/sm2/public-key
- /druid - /druid
- /algorithm-api/rainfall/grid - /algorithm-api/rainfall/grid
- /websocket/**
# 算法服务器配置 # 算法服务器配置
algorithm: algorithm:
+2
View File
@@ -42,10 +42,12 @@ safety:
no-encrypt-paths: no-encrypt-paths:
- /crypto/sm2/public-key - /crypto/sm2/public-key
- /algorithm-api/rainfall/grid - /algorithm-api/rainfall/grid
- /websocket/**
# 请求无需解密的路径 # 请求无需解密的路径
no-decrypt-paths: no-decrypt-paths:
- /crypto/sm2/public-key - /crypto/sm2/public-key
- /algorithm-api/rainfall/grid - /algorithm-api/rainfall/grid
- /websocket/**
# 算法服务器配置 # 算法服务器配置
algorithm: algorithm: