sockjsを使用して、STOMP over socketでSpring 4 WebSocketを使用しようとしています。そして、私は問題に直面しました。
私の構成:
websocket.xml - 春のコンテキストの一部
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/ws">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>
コントローラーコード:
@MessageMapping("/ws")
@SendTo("/topic/ws")
public AjaxResponse hello() throws Exception {
AjaxResponse ajaxResponse = new AjaxResponse();
ajaxResponse.setSuccess(true);
ajaxResponse.addSuccessMessage("WEB SOCKET!!! HELL YEAH!");
return ajaxResponse;
}
クライアント側:
var socket = new SockJS("<c:url value='/ws'/>");
var stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
alert('Connected: ' + frame);
stompClient.send("/app/ws", {}, {});
stompClient.subscribe('/topic/ws', function(response){
alert(response.success);
});
});
出力:
Opening Web Socket... stomp.js:130
GET http://localhost:8080/ws/info 404 (Not Found) sockjs-0.3.js:807
Whoops! Lost connection to undefined stomp.js:130
私は何を間違っていますか?
Google で例を見つけました (TickerStocks またはそのようなもの、あいさつアプリケーション (Spring の例)) で、すべて同じエラーが発生します。ハンドシェイクで(sockjsなしで)WebSocketを使用しようとしました-同じ結果です)。
追加情報:
public AjaxResponse hello();
ルート コンテキスト "/" の IndexController に配置されたメソッド。だから私はフルパスを提供することができます: http://localhost:8080/ws
. テスト済みの tomcat7 と tomcat8 をデプロイします。