From 9927546b781a695e8f5e7eff83b93b663fe19b76 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Fri, 3 Apr 2026 10:14:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20SSE=E8=BF=9E=E6=8E=A5=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=97=B6=E6=9C=BA=E6=8F=90=E5=89=8D=E8=87=B3=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E6=9C=80=E6=97=A9=E9=98=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加@Order(Ordered.HIGHEST_PRECEDENCE)确保最高优先级执行, 在Tomcat关闭前主动断开所有SSE连接,避免阻塞应用停止 --- .../com/youlai/boot/message/registry/SseSessionRegistry.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/youlai/boot/message/registry/SseSessionRegistry.java b/src/main/java/com/youlai/boot/message/registry/SseSessionRegistry.java index b0ef1487..502ec3a4 100644 --- a/src/main/java/com/youlai/boot/message/registry/SseSessionRegistry.java +++ b/src/main/java/com/youlai/boot/message/registry/SseSessionRegistry.java @@ -4,6 +4,8 @@ import com.youlai.boot.message.dto.OnlineUserDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.EventListener; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; @@ -199,6 +201,7 @@ public class SseSessionRegistry { /** * 容器关闭时主动断开所有 SSE 连接,避免阻塞应用停止 */ + @Order(Ordered.HIGHEST_PRECEDENCE) @EventListener(ContextClosedEvent.class) public void destroy() { int count = emitterUserMap.size();