Я разрабатываю API отдыха с использованием Spring Boot и Spring Websockets. Однако при запуске приложения я выдал следующую ошибку:
java.lang.AbstractMethodError: org.springframework.web.socket.server.support.WebSocketHandlerMapping.getPhase ()
Вот файл WebSocketConfig.java:
@Configuration
@EnableWebSocketMessageBroker
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("/connected").setAllowedOrigins("*").withSockJS();
}
}
Вот StompSessionHandler:
public class ConnectedStompSessionHandler extends StompSessionHandlerAdapter {
Logger logger=Logger.getLogger(ConnectedStompSessionHandler.class);
public ConnectedStompSessionHandler() {
super();
}
@Override
public Type getPayloadType(StompHeaders headers) {
return String.class;
}
@Override
public void handleFrame(StompHeaders headers, Object payload) {
//Message msg=(Message) payload;
logger.info("Received :" +payload);
}
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
logger.info("Connected to websocket");
}
@Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
logger.error("Got an exception",exception);
}
@Override
public void handleTransportError(StompSession session, Throwable exception) {
logger.error("Websocket transport error");
}
}
Вот контроллер веб-сокетов:
@Controller
public class ConnectedWebsocketController {
@MessageMapping("/connected/{topic}")
@SendTo("topic/messages")
public String send(@DestinationVariable("topic") String topic, String message){
return message;
}
}