From 892e3ee05451e24ffd8ad52c28ee0e5e7c281abf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E8=88=AA?= <653809315@qq.com>
Date: Mon, 8 Jan 2024 21:27:04 +0800
Subject: [PATCH] 1
---
pom.xml | 1 +
ruoyi-admin/pom.xml | 5 ++-
.../web/core/config/RadarStatusWebSocket.java | 5 ++-
.../web/core/config/WebSocketConfig.java | 31 +++++++++++++++++++
ruoyi-common/pom.xml | 2 --
5 files changed, 40 insertions(+), 4 deletions(-)
create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/core/config/WebSocketConfig.java
diff --git a/pom.xml b/pom.xml
index cbf322b..12c0ad1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -223,6 +223,7 @@
org.springframework.boot
spring-boot-starter-websocket
+ 3.0.2
diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml
index 2e28443..af32836 100644
--- a/ruoyi-admin/pom.xml
+++ b/ruoyi-admin/pom.xml
@@ -22,7 +22,10 @@
org.springframework.boot
spring-boot-starter-thymeleaf
-
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
org.springframework.boot
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/RadarStatusWebSocket.java b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/RadarStatusWebSocket.java
index b8b9503..973c960 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/RadarStatusWebSocket.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/RadarStatusWebSocket.java
@@ -1,12 +1,15 @@
package com.ruoyi.web.core.config;
+import org.springframework.stereotype.Component;
+
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
-@ServerEndpoint("/websocket")
+@ServerEndpoint(value="/websocket",configurator = WebSocketConfig.class)
+@Component
public class RadarStatusWebSocket {
private static Set sessions = new HashSet<>();
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/WebSocketConfig.java b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/WebSocketConfig.java
new file mode 100644
index 0000000..3e2668c
--- /dev/null
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/WebSocketConfig.java
@@ -0,0 +1,31 @@
+package com.ruoyi.web.core.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+import javax.servlet.http.HttpSession;
+import javax.websocket.HandshakeResponse;
+import javax.websocket.server.HandshakeRequest;
+import javax.websocket.server.ServerEndpointConfig;
+
+@Configuration
+public class WebSocketConfig extends ServerEndpointConfig.Configurator {
+
+// @Override
+// public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
+// HttpSession httpSession = (HttpSession)request.getHttpSession();
+// if (httpSession != null) {
+// // 读取session域中存储的数据
+// sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
+// }
+// super.modifyHandshake(sec, request, response);
+// }
+
+ @Bean
+ public ServerEndpointExporter serverEndpointExporter(){
+ return new ServerEndpointExporter();
+ }
+
+
+}
\ No newline at end of file
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index 0a9256a..f5a6be0 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -43,13 +43,11 @@
org.apache.shiro
shiro-ehcache
-
com.github.pagehelper
pagehelper-spring-boot-starter
-
org.springframework.boot