[英]spring boot websocket api 404 not found
在我的Spring Boot應用程序中,嘗試連接到ws
端點時,客戶端出現404
錯誤。
客戶端代碼
let wsUri = "ws://localhost:8080/chat"
let websocket = new WebSocket(wsUri);
彈簧配置
package coffee.web;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
registry.addHandler(chatServer(), "/chat");
}
@Bean
public ChatServer chatServer() {
return new ChatServer();
}
}
由於該請求是由調度程序Servlet處理的,因此是正常的http請求。 所以你需要在WebSocketConfig類中添加@Controller注釋
@Configuration
@EnableWebSocket
@Controller
public class WebSocketConfig implements WebSocketConfigurer
我遇到404錯誤,然后添加了控制器,然后隨着您的獲取,我得到了403,403就像訪問限制一樣,因此我為該端點刪除了CSRF過濾器,然后它開始工作。 我希望它會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.