NoSuchMethodError ResponseEntity $ BodyBuilder

时间:2019-08-29 09:56:29

标签: java

我正在尝试实现Web套接字以侦听服务器中的消息。我已经制作了一个示例项目,该项目可以成功运行,现在我正尝试将其移植到我们现有的代码库中。运行应用程序时,出现以下错误:

2019-08-29 09:34:33 - org.springframework.web.socket.sockjs.client.SockJsClient: [AWT-EventQueue-0] ERROR - Initial SockJS "Info" request to server failed, url=ws://localhost:8080/igip-gateway/messaging
java.lang.NoSuchMethodError: org.springframework.http.ResponseEntity.status(I)Lorg/springframework/http/ResponseEntity$BodyBuilder;
    at org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport.lambda$static$1(RestTemplateXhrTransport.java:158) ~[spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:496) ~[org.springframework.web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:465) ~[org.springframework.web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport.executeInfoRequestInternal(RestTemplateXhrTransport.java:137) ~[spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.socket.sockjs.client.AbstractXhrTransport.executeInfoRequest(AbstractXhrTransport.java:129) ~[spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.socket.sockjs.client.SockJsClient.getServerInfo(SockJsClient.java:294) ~[spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.socket.sockjs.client.SockJsClient.doHandshake(SockJsClient.java:260) ~[spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.socket.messaging.WebSocketStompClient.connect(WebSocketStompClient.java:268) [spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.web.socket.messaging.WebSocketStompClient.connect(WebSocketStompClient.java:249) [spring-websocket-5.1.9.RELEASE.jar:5.1.9.RELEASE]

我可以看到该方法作为spring-web-5.1.9.RELEASE.jar的一部分在外部库中作为类存在,当我使用verbose:class运行应用程序时,我只能看到对该jar的引用:

[Loaded org.springframework.http.converter.json.Jackson2ObjectMapperBuilder from file:/C:/DEV/m2/org/springframework/spring-web/5.1.9.RELEASE/spring-web-5.1.9.RELEASE.jar]
[Loaded org.springframework.http.converter.json.SpringHandlerInstantiator from file:/C:/DEV/m2/org/springframework/spring-web/5.1.9.RELEASE/spring-web-5.1.9.RELEASE.jar]
[Loaded org.springframework.http.HttpLogging from file:/C:/DEV/m2/org/springframework/spring-web/5.1.9.RELEASE/spring-web-5.1.9.RELEASE.jar]

如果相关,这也是我的代码:

    private static String URL = "ws://localhost:8080/gateway/messaging";

    public static void start() {
        StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
        List<Transport> transports = new ArrayList<>();
        transports.add(new WebSocketTransport(webSocketClient));
        WebSocketClient client = new SockJsClient(transports);
        WebSocketStompClient stompClient = new WebSocketStompClient(client);
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setThreadNamePrefix("Heart-Beat-Executor-");
        threadPoolTaskScheduler.setPoolSize(1);
        threadPoolTaskScheduler.initialize();
        stompClient.setTaskScheduler(threadPoolTaskScheduler);

        stompClient.setMessageConverter(new StringMessageConverter());

        StompHeaders connectHeaders = new StompHeaders();
        connectHeaders.setHeartbeat(new long[]{20000, 20000});
        connectHeaders.add("SECURITY-TOKEN", "token");

        StompSessionHandler sessionHandler = new CallListeningStompSessionHandler();
        ListenableFuture<StompSession> connect = stompClient.connect(URL, new WebSocketHttpHeaders(), connectHeaders, sessionHandler);
        System.out.println(connect);
    }
    public class CallListeningStompSessionHandler extends StompSessionHandlerAdapter {

        @Override
        public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
            StompHeaders connectHeaders = new StompHeaders();
            connectHeaders.add("SECURITY-TOKEN", "token");
            connectHeaders.add("destination", "/topic/services/user");
            session.subscribe(connectHeaders, this);
        }

        @Override
        public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
        }

        @Override
        public Type getPayloadType(StompHeaders headers) {
            return String.class;
        }

        @Override
        public void handleFrame(StompHeaders headers, Object payload) {
            System.out.println(payload);
        }

    }

我收到此错误的原因是什么?

0 个答案:

没有答案