SockJsClient 抛出 ClassCastException

SockJsClient throws ClassCastException

我正在尝试在我的 intellij IDEA 插件中配置 WebSocket 连接,我得到

 2019-10-25 19:17:56,835 [  81159]  ERROR - roject.impl.ProjectManagerImpl - From the listener com.homework.plugin.PluginTasksProjectComponent@1c0e28b2 (class com.homework.plugin.PluginTasksProjectComponent) 
java.lang.ClassCastException: com.fasterxml.jackson.module.kotlin.KotlinModule cannot be cast to com.fasterxml.jackson.databind.Module
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:811)
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:650)
    at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:633)
    at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59)
    at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:76)
    at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:150)
    at org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport.<init>(RestTemplateXhrTransport.java:64)
    at com.homework.plugin.chat.WebSocket.<init>(WebSocket.java:39)
    at com.homework.plugin.PluginTasksProjectComponent.projectOpened(PluginTasksProjectComponent.java:72)

当我在独立应用程序中使用此代码时,一切正常。

public class WebSocket {
private static final String TOPIC_ADDED = "/topic/discussion%s/comments/added";
private static final String TOPIC_UPDATED = "/topic/discussion%s/comments/updated";
private static final String TOPIC_DELETED = "/topic/discussion%s/comments/deleted";
private static final String TOPIC_SEND = "/topic/discussion%s/comments";
private final String URL = "https://my.url/stomp-messages";

private StompSession stompSession;
private StompSessionHandler sessionHandler;
private StompSession.Subscription currentSubscription;


public WebSocket(JTextPane messagesTextPane) {
    sessionHandler = new MySessionHandler(messagesTextPane);
    List<Transport> transports = new ArrayList<>(2);
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport());
    WebSocketClient client = new SockJsClient(transports);

    WebSocketStompClient stompClient = new WebSocketStompClient(client);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());

    try {
        stompSession = stompClient.connect(URL, sessionHandler).get();
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}

new RestTemplateXhrTransport() 创建对象的行抛出异常。 Jackson2ObjectMapperBuilder 尝试将一些 Kotlin 模块转换为 Module class,但我不明白为什么这段代码不在独立应用程序中执行。

可能有人知道问题的根源?

问题已解决。我应该添加这个依赖项

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-kotlin</artifactId>
    <version>2.10.0</version>
</dependency>