我正在尝试订阅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");});
});
}
答案 0 :(得分:-1)
@Kane这是我在spring-servlet.xml
<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;
}
}