一、问题描述
一次websocket连接调试中,触发了no mapping for get异常,检查连接路径后未发现问题;
二、问题解决
2.1 检查websocket注解
@serverendpoint("/path") @component public class websocketdemoserver { }
2.2 websocket相关配置补充
@configuration public class websocketconfig { @bean public serverendpointexporter serverendpointexporter() { return new serverendpointexporter(); } }
三、tips
当需要使用nginx转发websocket的时候需要的做如下配置
# websocket 相关配置 location /ws { proxy_pass http://127.0.0.1:9999; #协议版本。这儿必须写成这样 proxy_http_version 1.1; proxy_set_header upgrade $http_upgrade; proxy_set_header connection "upgrade"; #连接保持时常,600s内没有消息换发则连接断开 proxy_read_timeout 600s; }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论