突然失效的websocket

项目场景:

微服务项目Websocket连接


问题描述

好好的websocket为什么突然有一天就不行了

c 复制代码
2026-07-02 14:01:50.651 ERROR 3712 --- [nio-3004-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:3004/ws/web?token=ac01ba-3ecb-4192-9600-97ed4105ee28 - No 'jakarta.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?] with root cause

java.lang.IllegalArgumentException: No 'jakarta.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?
	at org.springframework.util.Assert.notNull(Assert.java:172) ~[spring-core-6.1.5.jar:6.1.5]
	at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getContainer(AbstractStandardUpgradeStrategy.java:70) ~[spring-websocket-6.1.5.jar:6.1.5]

原因分析:

分析1: 肯定是加了什么东西导致冲突
分析2:豆包
分析3:deepseek

总结: 都有提到 JSR-356,好嘛,好嘛,问了他们之后直接偏离路线至姥姥家。


解决方案:

解决1:不懂啊,他们两个说啥就是啥把,加注解,调参数,加依赖,然后并没有什么*用。
解决2:CSDN试试看,发现第一条博客嘤嘤嘤的猫和我的问题高度吻合,直至翻到最后一句话,好像打开了窗户一样舒服。抓紧回翻pom文件

解决:

快点去查看你的是不是4.2