detached
王宇航 2024-01-08 21:27:04 +08:00
parent 5b5fb4030a
commit 892e3ee054
5 changed files with 40 additions and 4 deletions

View File

@ -223,6 +223,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>3.0.2</version>
</dependency>
</dependencies>

View File

@ -22,7 +22,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -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<Session> sessions = new HashSet<>();

View File

@ -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();
}
}

View File

@ -43,13 +43,11 @@
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
</dependency>
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!-- 自定义验证注解 -->
<dependency>
<groupId>org.springframework.boot</groupId>