一、问题描述
一次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;
}