Spring WebSocket Stomp 整合Vue
描述:
将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
红框为浏览器向后台应用推送的消息
后台向浏览器推送的消息
微信公众号