亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶有 Spring Boot 的 JAVAX JSR 356 Websocket

帶有 Spring Boot 的 JAVAX JSR 356 Websocket

慕斯709654 2021-07-21 13:10:40
我正在嘗試在 Spring Boot 項目中使用 Javax JSR 356 API 實現服務器端 websocket 端點。我正在關注本教程。我知道在這個主題上有一些關于 SO 的問題,但我無法找到一個合理的解決方案。當我嘗試使用客戶端 (ARC) 連接到 websocket 時,它只報告“發生未知錯誤”。我檢查了嵌入式 Tomcat 服務器的日志,但沒有任何條目。根據 Tomcat 啟動條目,應用程序的上下文路徑為空 (""),因此我確定我使用正確的 URI 訪問了 websocket。這是我的代碼:@ServerEndpoint(value = "/socket", configurator = SpringConfigurator.class)public class WebSocketController{    @OnOpen    public void onOpen(Session session) throws IOException    {        System.out.println("Socket has been opened: " + session.getId());    }    @OnClose    public void onClose(Session session) throws IonException    {        System.out.println("Socket has been closed: " + session.getId());    }}Spring configuration class@Configurationpublic class WebSocketConfig{    @Bean    public WebSocketController webSocketController()    {        return new WebSocketController();    }    @Bean    public ServletContextAware endpointExporterInitializer(final ApplicationContext applicationContext) {        return new ServletContextAware() {            @Override            public void setServletContext(ServletContext servletContext) {                ServerEndpointExporter serverEndpointExporter = new ServerEndpointExporter();                serverEndpointExporter.setApplicationContext(applicationContext);                try {                    serverEndpointExporter.afterPropertiesSet();                } catch (Exception e) {                    throw new RuntimeException(e);                }            }        };    }}如何在 Spring Boot 應用程序中實現服務器端 websocket 端點?
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號