Websocket發消息出現Servlet.service() for servlet [dispatcherServlet] in context with path [] th


按網上說的, 什么配置 注解都齊了. 但還是不斷報這個錯.

網上spring整合websocket有兩種, 

一種是加入對javax中Websocket注解的處理;

另一種是spring的一套框架.

@Configuration
@EnableWebSocket
public class Config implements WebSocketConfigurer{

    /**
     * 注入一個ServerEndpointExporter,該Bean會自動注冊使用@ServerEndpoint注解申明的websocket endpoint
     */
    @Bean
    public TextWebscokect getHandle() {
        return new TextWebscokect();
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(getHandle(), "/textws","/websokect/textws").setAllowedOrigins("*");    
    }

}

我本來用的第一種, 但是出問題, 不斷嘗試中換成了第二種, 事后想來, 兩種應該都能用.

 

至於問題出現的原因: 這個框架是前后端分離的, 后端端口是8082, 前端vue頁面應該訪問node.js服務器, 是3000.

我一直在頁面向8082端口訪問, 但就報標題的錯....弄了一上午, 發現是Websocket的url應該訪問3000的端口, 然后node轉發后端, 不然就報錯....

this.ws=new KsyWebSocket("test","ws://localhost:3000/api/textws")
//這是我寫的一個WebSocket前端類, 整合了一下, 這是正確url....

 


免責聲明!

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



猜您在找 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause ------>Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause 錯誤:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] SEVERE: Servlet.service() for servlet [SpringMVC] in context with path [] threw exception ........ ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [log,175] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception thymeleaf: Could not parse as expression: "" Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.Nul 關於Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause錯誤提示 報錯:嚴重: Servlet.service() for servlet [springmvc] in context with path [ ] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause ERROR .web.servlet.DispatcherServlet - Context initialization failed 【錯誤日志】嚴重: Servlet.service() for servlet SpringDispatcherServlet threw exception java.lang.IllegalArgumen
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM