探究springboot集成websocket,连接不上,使用netty-websocket却能连接上

原因:集成spring-security了。把websocket请求拦截了,且不输出日志(因为一般spring相关日志级别是warn。debug模式下日志太多了

然后可以修改undertow日志级别看日志

bash 复制代码
# 日志配置
logging:
  level:
    com.cas.wict: debug
    org.springframework: warn
    org.springframework.web: debug
    io.undertow: debug

关键日志输出

bash 复制代码
2024-07-11 10:15:43.292 [XNIO-1 task-1] DEBUG io.undertow.request.security
 - Attempting to authenticate /ws, authentication required: false
2024-07-11 10:15:43.293 [XNIO-1 task-1] DEBUG io.undertow.request.security
 - Authentication outcome was NOT_ATTEMPTED with method io.undertow.security.impl.CachedAuthenticatedSessionMechanism@7fedbc60 for /ws
2024-07-11 10:15:43.293 [XNIO-1 task-1] DEBUG io.undertow.request.security
 - Authentication result was ATTEMPTED for /ws

发现可能是security对ws请求路径进行了拦截(为什么会拦截,猜测虽然写的是ws,但是发起的时候还是http,由后台升级成websocket)

解决办法:放开验证,单独写过滤器验证ws的请求

为什么以前用netty-websocket可以连接,那是因为netty没走spring-security的过滤器链

相关推荐
凤山老林4 小时前
Spring Boot 启动冲刺:耗时剖析、懒加载策略与事件驱动初始化优化
spring boot·后端·python
云梦谭8 小时前
WebSocket 协议详解:从 HTTP 握手到全双工通信
websocket·网络协议·http
萧瑟余晖11 小时前
Spring Security会话管理与CSRF详解
spring·csrf
Wx-bishekaifayuan12 小时前
springboot铜仁非遗之家76938-计算机课程设计、毕业设计
java·spring boot·后端·spring·django·课程设计·旅游
顽疲12 小时前
java vue springboot 养老系统源码详解:退住 care_out 审批结算与腾床事务实践
java·vue.js·spring boot·vue养老·springboot养老·java养老
青春不朽51213 小时前
Python 里 a is b 有时 True 有时 False?小整数缓存和常量折叠的底层真相
python·spring·缓存
苏渡苇13 小时前
Spring Insight:跨服务调用链路是怎么串起来的?
spring boot·后端·spring·系统监控·apm