SpringBoot WebSocket連接報no mapping for GET問題
更新時間:2025年02月24日 09:45:54 作者:lijiabin417
文章描述了一個在調試WebSocket連接時遇到的`nomappingforGET`異常問題,并提供了問題解決的方法,包括檢查WebSocket注解和補充相關配置,此外,還特別提到了在使用Nginx轉發(fā)WebSocket時所需的配置
一、問題描述
一次websocket連接調試中,觸發(fā)了no mapping for GET異常,檢查連接路徑后未發(fā)現(xiàn)問題;
二、問題解決
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轉發(fā)websocket的時候需要的做如下配置
# Websocket 相關配置
location /ws {
proxy_pass http://127.0.0.1:9999;
#協(xié)議版本。這兒必須寫成這樣
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#連接保持時常,600s內沒有消息換發(fā)則連接斷開
proxy_read_timeout 600s;
}總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
通過使用Byte?Buddy便捷創(chuàng)建Java?Agent
這篇文章主要為大家介紹了如何通過使用Byte?Buddy便捷創(chuàng)建Java?Agent的使用說明,有需要的朋友可以借鑒參考下希望能夠有所幫助,祝大家多多進步2022-03-03

