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

相关推荐
程序员小蛋3 分钟前
基于springboot宠物咖啡馆平台的设计与实现.7z(源码+论文)
spring boot·后端·宠物
爱码少年6 分钟前
Springboot 工程中快速判断web应用服务器类型
java·spring boot
禾小西18 分钟前
Knife4j 快速入门:集Swagger2 和 OpenAPI3 为一体的增强解决方案
java·spring boot·后端
polaris063019 分钟前
Docker部署Spring Boot + Vue项目
vue.js·spring boot·docker
心勤则明19 分钟前
Spring AI Alibaba MCP 协议的全链路安全与动态鉴权
java·安全·spring
weixin_7042660527 分钟前
Spring Boot (整合 Mybatis + 自动配置原理)
spring boot·笔记·mybatis
一叶飘零_sweeeet29 分钟前
吃透 Spring Boot 3 + Spring Cloud 云原生新特性
spring boot·spring cloud·架构
ai产品老杨35 分钟前
源码级赋能:基于Spring Boot/Vue的企业级AI视频平台二次开发实战与架构解析(GB28181/边缘计算/算法商城)
vue.js·人工智能·spring boot
xianjian09121 小时前
Java进阶-在Ubuntu上部署SpringBoot应用
java·spring boot·ubuntu
拾荒的小海螺1 小时前
JAVA:Spring Boot3 集成 Spring AI 实现 Prompt 提示词工程
java·spring boot·spring