Springboot整合WebSocket常见问题解决

Springboot整合WebSocket常见问题解决

1. 启动失败报错
  • 现象
java.lang.IllegalStateException: Failed to register @ServerEndpoint class: class com.xxx.WebSocketServer$$EnhancerBySpringCGLIB$$62689f33
 
javax.websocket.DeploymentException: Cannot deploy POJO class [com.xxx.WebSocketServer$$EnhancerBySpringCGLIB$$62689f33] as it is not annotated with @ServerEndpoint
  • 问题原因
	由于程序使用AOP切面,切面范围包括了@ServerEndpoint注解所在的类
  • 解决方案
	可参考如下链接博主的分析,非常详细
	参考链接:https://blog.csdn.net/qq_15807785/article/details/83547978
2. 客户端无法和WebSocket服务端建立连接
  • 现象
	通过ws://localhost:port/ws/name无法和服务端进行建立连接
  • 问题原因
	可能存在两个原因:
	1. springboot程序配置了server.servlet.context-path
	2. 使用shiro等权限控制框架对请求进行了拦截
  • 解决方案
	1. ws://localhost:port/ws/name地址中加入server.servlet.context-path配置的前缀
	2. 在shiro权限框架中将websocke使用地址忽略权限校验
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值