WebSocketAnnotationMethodMessageHandler 没有匹配的方法
WebSocketAnnotationMethodMessageHandler No matching methods
我正在使用 Stomp 编写 WebSocket 客户端,当我使用 Stomp 客户端发送请求时,日志输出是:
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.}
这说明客户端没有问题。而且服务器找不到匹配的URL来处理request.But我已经有一个处理method.This是代码:
@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);
}
}
}
这是我的网络配置:
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();
}
}
这是客户端代码:
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"));
我该怎么办?可能哪里出错了?
PS:控制器WebSocketController
已经自动扫描。
JDK:1.8
Tomcat:8.0.36
Spring:4.2.6
这个问题我纠结了2天
确保控制器是自动扫描的 successfully.I 我遇到这个问题是因为 bean 不是 scan.So 无法匹配 属性 方法来处理 stomp 客户端 request.Check 自动扫描configuration.Seach 历史日志内容,汇总的详细信息为here。
我正在使用 Stomp 编写 WebSocket 客户端,当我使用 Stomp 客户端发送请求时,日志输出是:
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.}
这说明客户端没有问题。而且服务器找不到匹配的URL来处理request.But我已经有一个处理method.This是代码:
@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);
}
}
}
这是我的网络配置:
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();
}
}
这是客户端代码:
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"));
我该怎么办?可能哪里出错了?
PS:控制器WebSocketController
已经自动扫描。
JDK:1.8 Tomcat:8.0.36 Spring:4.2.6
这个问题我纠结了2天
确保控制器是自动扫描的 successfully.I 我遇到这个问题是因为 bean 不是 scan.So 无法匹配 属性 方法来处理 stomp 客户端 request.Check 自动扫描configuration.Seach 历史日志内容,汇总的详细信息为here。