WebSocket connection to '*' failed: Error during WebSocket handshake: Unexpected response code: 404

狂风中的少年 提交于 2020-02-27 16:35:38

Spring boot 2.0配置WebSocket 出现WebSocket connection to 'ws://localhost:8080/websocket/3c9d8e1e0cf24bfdbc65b8f24367def3' failed: Error during WebSocket handshake: Unexpected response code: 404

 

1.首先排查路径是否正确;

2.如果路径没有问题, 检查是否配置ServerEndpointExporter;

@Component
public class WebSocketConfig {
    /**
     * ServerEndpointExporter 作用
     *
     * 这个Bean会自动注册使用@ServerEndpoint注解声明的websocket endpoint
     *
     * @return
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

}

WebSocket 注册的bean默认是自己管理,没有托管给spring。需要将WebSocket的bean托管给spring容器。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!