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

相关推荐
eternal__day12 分钟前
Spring Cloud 多机部署与负载均衡实战详解
java·spring boot·后端·spring cloud·负载均衡
程序员秘密基地22 分钟前
基于vscode,idea,java,html,css,vue,echart,maven,springboot,mysql数据库,在线考试系统
java·vue.js·spring boot·spring·web app
吾日三省吾码41 分钟前
Spring 团队详解:AOT 缓存实践、JSpecify 空指针安全与支持策略升级
java·spring·缓存
风象南1 小时前
SpringBoot的5种日志输出规范策略
java·spring boot·后端
梁云亮2 小时前
Spring Boot + Thymeleaf 防重复提交
spring boot·防抖·防重复提交
花月C3 小时前
Mysql-定时删除数据库中的验证码
数据库·后端·mysql·spring
XMYX-08 小时前
Spring Boot + Prometheus 实现应用监控(基于 Actuator 和 Micrometer)
spring boot·后端·prometheus
@yanyu66610 小时前
springboot实现查询学生
java·spring boot·后端
酷爱码11 小时前
Spring Boot项目中JSON解析库的深度解析与应用实践
spring boot·后端·json
java干货11 小时前
虚拟线程与消息队列:Spring Boot 3.5 中异步架构的演进与选择
spring boot·后端·架构