探究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的过滤器链

相关推荐
Mryan20052 小时前
解决GraalVM Native Maven Plugin错误:JAVA_HOME未指向GraalVM Distribution
java·开发语言·spring boot·maven
VX_CXsjNo12 小时前
免费送源码:Java+SSM+Android Studio 基于Android Studio游戏搜索app的设计与实现 计算机毕业设计原创定制
java·spring boot·spring·游戏·eclipse·android studio·android-studio
小小鸭程序员3 小时前
Vue组件化开发深度解析:Element UI与Ant Design Vue对比实践
java·vue.js·spring·ui·elementui
陌路物是人非3 小时前
SpringBoot + Netty + Vue + WebSocket实现在线聊天
vue.js·spring boot·websocket·netty
穿林鸟5 小时前
Spring Boot项目信创国产化适配指南
java·spring boot·后端
伏游5 小时前
【BUG】生产环境死锁问题定位排查解决全过程
服务器·数据库·spring boot·后端·postgresql·bug
hycccccch6 小时前
Springcache+xxljob实现定时刷新缓存
java·后端·spring·缓存
爱的叹息6 小时前
SpringBoot集成Redis 灵活使用 TypedTuple 和 DefaultTypedTuple 实现 Redis ZSet 的复杂操作
spring boot·redis·bootstrap
网络安全天地6 小时前
使用 Flutter 制作地图应用
websocket·网络协议·tcp/ip·http·网络安全·https·udp
wisdom_zhe6 小时前
Spring Boot 日志 配置 SLF4J 和 Logback
java·spring boot·logback