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

相关推荐
Billow_lamb33 分钟前
Spring Boot2.x.x 全局错误处理
java·spring boot·后端
雁于飞1 小时前
分布式基础
java·spring boot·分布式·spring·wpf·cloud native
bing_1581 小时前
Spring Boot 项目中判断集合(List、Set、Map)不能为空且不为 null的注解使用
spring boot·后端·list
Q_Q5110082854 小时前
python+django/flask的结合人脸识别和实名认证的校园论坛系统
spring boot·python·django·flask·node.js·php
Q_Q5110082854 小时前
python+django/flask的选课系统与课程评价整合系统
spring boot·python·django·flask·node.js·php
老华带你飞4 小时前
社区养老保障|智慧养老|基于springboot+小程序社区养老保障系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序·毕设·社区养老保障
q***87604 小时前
springboot下使用druid-spring-boot-starter
java·spring boot·后端
东南门吹雪4 小时前
Spring的Bean相关
java·spring·bean·aop
q***69774 小时前
Y20030018基于Java+Springboot+mysql+jsp+layui的家政服务系统的设计与实现 源代码 文档
java·spring boot·mysql
2***57424 小时前
前端WebSocket案例
网络·websocket·网络协议