Search code examples
javaspringwebsocketstomp

WebSocketAnnotationMethodMessageHandler No matching methods


I am writing a WebSocket client using Stomp,When I am sending a request using Stomp client,the log output is :

15:17:44.688]-[clientInboundChannel-59]-[org.springframework.web.socket.messaging.WebSocketAnnotationMethodMessageHandler]-{Searching methods to handle SEND /app/vehicle session=qnlerizz}
15:17:44.688]-[clientInboundChannel-59]-[org.springframework.web.socket.messaging.WebSocketAnnotationMethodMessageHandler]-{No matching methods.}

This shows the client is no problem. And the server can not find matching URL to handle the request.But I am already had a handle method.This is the code:

@Controller
@Log4j2
public class WebSocketController {

    public SimpMessagingTemplate template;

    @Autowired
    public WebSocketController(SimpMessagingTemplate template) {
        this.template = template;
    }       

    @MessageMapping("/vehicle")
    @SendTo("/topic/location")
    public void getloc() throws Exception {
        try {
            for (int i = 0; i < 10; i++) {
                template.convertAndSend("/topic/location", "aaaaaaa");
            }
        } catch (Exception e) {
            log.error(e);
        }
    }
}

This is my web configuration:

public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {           
        config.enableSimpleBroker("/topic");            
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/vehicle").withSockJS();           
    }
}

This is the client code:

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

stompClient.send("/app/vehicle",{},JSON.stringify("bbb"));

What should I do?Where maybe going wrong?

PS:The controller WebSocketController is already auto scan.

JDK:1.8 Tomcat:8.0.36 Spring:4.2.6

I am struggle to this question for 2 day.


Solution

  • Make sure that the controller is autoscan successfully.I am encount this problem because the bean is not scan.So can not match the property method to handle the stomp client request.Check the auto scan configuration.Seach the history log content,the summerized detail is here.