webSocket連接錯誤原因


1、在SSM架構中正常使用的代碼,遷移到Spring Boot中出現錯誤

我是@ServerEndpoint注解方式實現

這里寫圖片描述

報錯:

這里寫圖片描述

這絕對是個坑!!!

錯誤原因:要注入ServerEndpointExporter,這個bean會自動注冊使用了@ServerEndpoint注解聲明的Websocket endpoint。要注意,如果使用獨立的servlet容器,而不是直接使用springboot的內置容器,就不要注入ServerEndpointExporter,因為它將由容器自己提供和管理。

解決方式:加入這個配置

@Configuration
public class WebSocketConfig {
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
 }

 轉載:https://blog.csdn.net/qq_24283811/article/details/80584879


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM