我按照教程创建了测试项目。
@Configuration
@EnableWebSocketMessageBroker
public class WSConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat");
registry.addEndpoint("/chat").withSockJS();
}
@Controller
public class WSController {
@MessageMapping("/chat")
@SendTo("/topic/messages")
public String send(String message) throws Exception {
return "test";
}
}
我无法连接Postman,我尝试了不同的URL:
ws://localhost:8080
ws://localhost:8080/app
ws://localhost:8080/app/chat
每次我点击连接按钮时,都会得到404响应。我做错了什么?(我是WebSocket的新手)