【WebSocket】SpringBoot中,WebSocket客戶端連接服務端時,出現SockJsException: Uncaught failure in SockJS...異常信息

錯誤信息:

2019-01-18 10:58:32.094 ERROR 11113 --- [nio-8086-exec-9] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/energymanagement] threw exception [Request processing failed; nested exception is org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=http://192.168.168.180:8086/xxxxx/socket/690/a4o3vo4b/xhr?t=1547780328164; nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: Failed to open session; nested exception is java.lang.IllegalArgumentException: Async support must be enabled on a servlet and for all filters involved in async request processing. This is done in Java code using the Servlet API or by adding "<async-supported>true</async-supported>" to servlet and filter declarations in web.xml. Also you must use a Servlet 3.0+ container] with root cause

java.lang.IllegalArgumentException: Async support must be enabled on a servlet and for all filters involved in async request processing. This is done in Java code using the Servlet API or by adding "<async-supported>true</async-supported>" to servlet and filter declarations in web.xml. Also you must use a Servlet 3.0+ container

....//省略其他異常信息

at com.xxxxxx.energymanagement.CrossFilter.doFilter(CrossFilter.java:37) ~[classes!/:0.0.1-SNAPSHOT]

.....//省略其他異常信息

錯誤中,只有這一句是關於項目中文件,而且是一個Fileter

 

錯誤原因:

具體原因不清楚,可以參考https://www.cnblogs.com/guangshan/p/4916993.html該博主的分享

 

錯誤解決:

在項目中的所有Filter中的@WebFilter增加異步支持asyncSupported=true

EG:@WebFilter(filterName = "CrossFilter", urlPatterns = "/*",asyncSupported=true)

同時在項目的啓動類增加@EnableAsync註解。經測試,此方法可以解決該異常。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章