From 184ae3b061765e8fbe54bcef06b67c6b4f2e024c Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期一, 11 九月 2023 09:52:40 +0800 Subject: [PATCH] 拉取新版本 --- springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java b/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java index 697d697..8749b5e 100644 --- a/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java +++ b/springboot-vue3/src/main/java/com/example/springboot/component/WebSocketServer.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; + +import org.apache.catalina.core.ApplicationContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,8 +18,8 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.stereotype.Component; - import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @@ -25,6 +27,17 @@ @ServerEndpoint(value = "/api/talk/{username}") @Component public class WebSocketServer { + + // @Autowired + // HomeMapper homeMapper; + + static ConfigurableApplicationContext applicationContext; + + //瑙e喅鏃犳硶娉ㄥ叆mapper闂 //浣跨敤鏂规硶 homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class); + public static void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext) { + WebSocketServer.applicationContext = configurableApplicationContext; + } + private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class); private List<String> messages; @@ -86,6 +99,7 @@ jsonObject.set("message", text); this.messages.add(text); this.sendMessage(jsonObject.toString()); //JSONUtil.toJsonStr(jsonObject) + } @OnError @@ -122,6 +136,7 @@ public List<String> getMessages() { return messages; + } public void clearMessages() { -- Gitblit v1.8.0