如何解决“失败:WebSocket握手期间出错:弹出websockets中的意外响应代码:200”?

时间:2017-03-28 07:26:30

标签: spring-mvc stomp spring-websocket sockjs spring-messaging

我正在尝试订阅spring网络套接字中的特定频道,但在使用SockJs指向网址时出现以下错误WebSocket connection to 'ws://localhost:8080/Spring/rest/user/chat/045/jmfz3b3j/websocket' failed: Error during WebSocket handshake: Unexpected response code: 200请帮我避免这种情况。 这是我订阅的客户端代码。

Index.jsp

var stompClient =null;
      function subscribe(){ 
var socket = new SockJS('/Spring/rest/user/chat');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
     console.log('Connected: ' + frame);
     stompClient.subscribe('/topic/messages', function(test) {
     	 alert("in call back function");});
 });
 }

1 个答案:

答案 0 :(得分:-1)

@Kane这是我在spring-servlet.xml

中的websocket配置
<websocket:message-broker application-destination-prefix="/app" >
    <websocket:stomp-endpoint path="/chat" allowed-origins="*">
        <websocket:sockjs />
    </websocket:stomp-endpoint>
    <websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>

这是我的controller代码

@Controller
@RequestMapping("user")
public class OptnCptController{
    @MessageMapping("topic/messages")
    public String getMsg(String s)
    {
        return s;
    }
}