项目中配置了支持sockjs:
stompEndpointRegistry // ------------------------------------------------------------------
.addEndpoint("/stomp") // 将/serviceName/stomp/websocket路径注册为STOMP的端点
.setAllowedOrigins("*") // 可以跨域
.addInterceptors(handshakeInterceptor) // 自己定义的获取httpsession的拦截器
.setHandshakeHandler(handshakeHandler) // 封装认证用户信息
.withSockJS() // 支持socktJS访问
; // --------------------------------------------------------------------------------------
此时,websocket的连接方式分两种:
1. 浏览器支持websocket,则连接地址为: http://localhost:8080/stomp/websocket
2. 浏览器不支持websocket,采用sockjs方式,则连接地址为: http://localhost:8080/stomp