Spring WebSocket 与 Spring Cloud Gateway 同时使用踩坑及修复

未配置协议导致只转发 HTTP
解决方法是把协议从 lb://
改为 lb:ws(s)://
1 | spring: |
class org.apache.catalina.connector.ResponseFacade cannot be cast to class reactor.netty.http.server.HttpServerResponse (org.apache.catalina.connector.ResponseFacade and reactor.netty.http.server.HttpServerResponse are in unnamed module of loader ‘app’)
参见 spring-cloud/spring-cloud-gateway#2039
依赖冲突,我这里是 spring-boot-starter-web
引入了 Tomcat Embed Core 导致 Gateway 使用 Tomcat 而不是 Netty,解决方案是排除依赖项:
1 | dependencies { |
可以使用命令
1 ./gradlew <项目>:dependencies --configuration runtimeClasspath > dependencies_runtime.txt输出运行时依赖关系,查找是哪个依赖引入了 Tomcat Embed Core
- 标题: Spring WebSocket 与 Spring Cloud Gateway 同时使用踩坑及修复
- 作者: 夏沫花火zzz🌙 (Muska_Ami)
- 创建于 : 2025-06-14 13:57:47
- 更新于 : 2025-06-23 04:42:28
- 链接: https://blog.1l1.icu/2025/06/14/spring-websocket-yu-spring-cloud-gateway-tong-shi-shi-yong-cai-keng-ji-xiu-fu/
- 版权声明: 本文章采用 CC BY-SA 4.0 进行许可。
评论