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

相关推荐
程序员大金24 分钟前
基于SpringBoot+Vue+MySQL的影院购票系统
java·vue.js·spring boot·后端·mysql·mybatis
ོ1842 小时前
苍穹外卖——day1
spring
mqiqe2 小时前
Spring JPA 注解@Id @GeneratedValue @GenericGenerator
java·数据库·spring
工业甲酰苯胺3 小时前
Springboot中自定义监听器
java·spring boot·spring
一粟1024 小时前
Spring Boot:现代化Java应用开发的艺术
java·spring boot·后端
码农小伙4 小时前
Spring-bean的生命周期-尾篇
java·后端·spring
IT研究室4 小时前
计算机毕业设计选题推荐-校园车辆管理系统-Java/Python项目实战(亮点:数据可视化分析、账号锁定)
java·spring boot·python·django·毕业设计·源码·课程设计
coffee_baby4 小时前
桥接模式详解和分析JDBC中的应用
java·数据库·spring boot·java-ee·桥接模式
有一个好名字5 小时前
后端Controller获取成功,但是前端报错404
前端·spring
SuperherRo5 小时前
spring综合性利用工具-SpringBootVul-GUI(五)
spring boot·spring·漏洞利用·信息泄露