Spring 4 WebSocket app

后端 未结 2 1098
猫巷女王i
猫巷女王i 2020-12-31 23:56

I tried to run this example from the spring site: tutorial except the Spring Boot part.

Web.xml


    Archetype C         


        
相关标签:
2条回答
  • 2021-01-01 00:12

    Also if you want not to pass login/password to server (as you might rely on Spring security) then you shouldn't use

    stompClient.connect('', '', function(frame) {
    

    but instead

    stompClient.connect({}, function(frame) {
    

    Take a look here: https://github.com/spring-guides/gs-messaging-stomp-websocket/issues/10

    0 讨论(0)
  • 2021-01-01 00:38

    The mistake was wrong controller mapping. I have:

      @MessageMapping("/hello")
        @SendTo("/topic/greetings")
        public Greeting greeting(HelloMessage message) throws Exception
    

    and in the jsp:

    stompClient.subscribe("<c:url value='/topic/greetings'/>", function(greeting){...
    

    and

    stompClient.send("<c:url value='/app/hello'/>", {}, JSON.stringify({ 'name': name }));
    

    The right ones are:

    stompClient.subscribe('/topic/greetings', function(greeting){...
    stompClient.send('/app/hello', {}, JSON.stringify({ 'name': name }));
    

    The c:url adds the root of the project, when I removed it the app worked. However c:url(the root) is rquired when create new socket with SockJs here:

    var socket = new SockJS("<c:url value='/hello'/>");
    
    0 讨论(0)
提交回复
热议问题