不能完全算是bug,但是确实浪费了我一天时间,暂且记下来罢。
环境
pom.xml 部分
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
Tomcat 10.0.51
Bug
前端通过websocket连接后端失败,经过反复排查,代码逻辑没有问题。翻遍互联网都没有找到解决方案。
解决
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
原因
原因是软件版本不匹配(or 不兼容?)。在Tomcat官网上找到如下一段话。2017年Oracle决定把Java EE开源,给Eclipse基金会。Java EE的新名字就叫Jakarta EE。
Users of Tomcat 10 onwards should be aware that, as a result of the move from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.*
to jakarta.*
.
| Servlet Spec | JSP Spec | EL Spec | WebSocket Spec | Authentication (JASIC) Spec | Apache Tomcat Version | Latest Released Version | Supported Java Versions |
|---|---|---|---|---|---|---|---|
| 6.0 | 3.1 | 5.0 | TBD | TBD | 10.1.x | 10.1.0-M5 (alpha) | 11 and later |
| 5.0 | 3.0 | 4.0 | 2.0 | 2.0 | 10.0.x | 10.0.11 | 8 and later |
| 4.0 | 2.3 | 3.0 | 1.1 | 1.1 | 9.0.x | 9.0.53 | 8 and later |
| 3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 8.5.x | 8.5.71 | 7 and later |
| 3.1 | 2.3 | 3.0 | 1.1 | N/A | 8.0.x (superseded) | 8.0.53 (superseded) | 7 and later |
| 3.0 | 2.2 | 2.2 | 1.1 | N/A | 7.0.x (archived) | 7.0.109 (archived) | 6 and later (7 and later for WebSocket) |
| 2.5 | 2.1 | 2.1 | N/A | N/A | 6.0.x (archived) | 6.0.53 (archived) | 5 and later |
| 2.4 | 2.0 | N/A | N/A | N/A | 5.5.x (archived) | 5.5.36 (archived) | 1.4 and later |
| 2.3 | 1.2 | N/A | N/A | N/A | 4.1.x (archived) | 4.1.40 (archived) | 1.3 and later |
| 2.2 | 1.1 | N/A | N/A | N/A | 3.3.x (archived) | 3.3.2 (archived) | 1.1 and later |
无独有偶,前两天给spring配kafka的环境时,也看到过类似的适配性问题,但由于当时看了看文档,避免了问题的出现。
| Spring for Apache Kafka Version | Spring Integration for Apache Kafka Version | kafka-clients | Spring Boot |
|---|---|---|---|
| 2.7.x | 5.4.x | 2.7.0 or 2.8.0 | 2.4.x or 2.5.x |
| 2.6.x | 5.3.x or 5.4.x | 2.6.0 | 2.3.x or 2.4.x |
| 2.5.x | 3.3.x | 2.5.1 | 2.3.x |
| 2.4.x~~~~ | 3.2.x~~~~ | 2.4.1~~~~ | 2.2.x (End of Life)~~~~ |
| 2.3.x~~~~ | 3.2.x~~~~ | 2.3.1~~~~ | 2.2.x (End of Life)~~~~ |
| 2.2.x~~~~ | 3.1.x~~~~ | 2.0.1, 2.1.x, 2.2.x~~~~ | 2.1.x (End of Life)~~~~ |
| 2.1.x | 3.0.x | 1.0.2 | 2.0.x (End of Life) |
| 1.3.x~~~~ | 2.3.x~~~~ | 0.11.0.x, 1.0.x~~~~ | 1.5.x (End of Life) |
小结
不要随随便便配环境,配环境之前,多看看文档,确认相应的版本是否稳定、是否匹配。
文章转载自咕呱叫声唧唧唧,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




