簡體   English   中英

Spring 4 Websocket和腳踩-控制器未達到

[英]Spring 4 websocket And stomp - controller is not reached

我正在使用spring的官方示例(問候示例):

http://spring.io/guides/gs/messaging-stomp-websocket/

一切似乎都正常,當我按連接時,我可以看到連接已建立,服務器已經連接好了。

但是,在連接后,當我向服務器提交“名稱”時,我沒有收到任何錯誤,也沒有任何請求到達GreetingController。

我試圖使日志級別處於跟蹤狀態,並且在執行“發送”時看到以下幾行:

22 Ar 2014 17:10:52 DEBUG DispatcherServlet - Successfully completed request
22 Apr 2014 17:10:52 DEBUG ExceptionTranslationFilter - Chain processed normally
22 Apr 2014 17:10:52 DEBUG HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
22 Apr 2014 17:10:52 DEBUG SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
22 Apr 2014 17:10:52 DEBUG LoggingWebSocketHandlerDecorator - Connection established, SockJS session id=taxwn2fu, uri=/MyWebApp/hello/535/taxwn2fu/websocket
22 Apr 2014 17:10:52 DEBUG SubProtocolWebSocketHandler - Started WebSocket session=taxwn2fu, number  of sessions=1
22 Apr 2014 17:10:53 DEBUG StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=CONNECT, nativeHeaders={heart-beat=[10000,10000], accept-version=[1.1,1.0]}, simpMessageType=CONNECT,  id=0686dda9-afa3-7a54-756c-89279ea33126, timestamp=1398175853000}]
22 Apr 2014 17:10:53 DEBUG StompEncoder - Encoded STOMP command=CONNECTED headers={heart-beat=[0,0], version=[1.1]}
22 Apr 2014 17:10:53 DEBUG StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=SUBSCRIBE, nativeHeaders={id=[sub-0], destination=[/topic/greetings]}, simpMessageType=SUBSCRIBE, simpSubscriptionId=sub-0, simpDestination=/topic/greetings, id=653538d3-0722-0325-2c23-8314abd70cc0, timestamp=1398175853008}]
22 Apr 2014 17:10:53 DEBUG DefaultSubscriptionRegistry - Adding subscription id=sub-0, destination=/topic/greetings
22 Apr 2014 17:10:56 DEBUG StompDecoder - Decoded [Payload byte[17]][Headers={stompCommand=SEND, nativeHeaders={content-length=[17], destination=[/app/hello]}, simpMessageType=MESSAGE, simpDestination=/app/hello, id=f9a608c0-6e02-7828-a057-a6b2b07b6af7, timestamp=1398175856489}]
22 Apr 2014 17:10:56 DEBUG SimpAnnotationMethodMessageHandler - Handling message, lookupDestination=/hello

有任何想法嗎?

PS,這是我使用的js代碼的一部分(與網站相同):

    function connect() {
        var socket = new SockJS('/MyWebApp/hello');
        stompClient = Stomp.over(socket);
        stompClient.connect({}, function(frame) {
            setConnected(true);
            console.log('Connected: ' + frame);
            stompClient.subscribe('/topic/greetings', function(greeting){
                showGreeting(JSON.parse(greeting.body).content);
            });
        });
    }

    function disconnect() {
        stompClient.disconnect();
        setConnected(false);
        console.log("Disconnected");
    }

    function sendName() {
        debugger;
        var name = document.getElementById('name').value;
        stompClient.send("/app/hello", {}, JSON.stringify({ 'name': name }));
    }

好的,服務器正在捕獲消息,但是它並沒有執行任何操作,因此,我認為您應該:

  1. 注意這一行“ config.setApplicationDestinationPrefixes(“ / app”);“ 在WebSocketConfig類上;
  2. 確保您的Controller帶有@Controller,方法帶有@MessageMapping(“ / hello”);

好的,我有一個spring配置問題,我沒有掃描必要的bean目錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM