描述:
將websocket應用在實際的項目中,用於后台應用向瀏覽器推送消息。
架構:
傳統的springmvc基於xml配置的(但是websocket配置是基於java config配置,可以穿插的配置),前端采用vue.js.
啟動報錯:
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‘
解決:
需要在你的web.xml中所有的servlet和filter中添加<async-supported>true</async-supported>
引入依賴:spring版本需要4.x
webscoket相關配置
WebSocketStompConfig.java 用於配置webscoket
MessageService.java 后台向前端推送消息類
ReceiveClientController.java 接收前端發送的消息
前端vue
紅框為瀏覽器向后台應用推送的消息
后台向瀏覽器推送的消息
微信公眾號