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