我正在尝试在我的intellij IDEA插件中配置WebSocket连接,我得到
func imageIsEmpty(_ image: UIImage) -> Bool {
guard let cgImage = image.cgImage,
let dataProvider = cgImage.dataProvider else
{
return true
}
let pixelData = dataProvider.data
let data: UnsafePointer<UInt8> = CFDataGetBytePtr(pixelData)
let imageWidth = Int(image.size.width)
let imageHeight = Int(image.size.height)
for x in 0..<imageWidth {
for y in 0..<imageHeight {
let pixelIndex = ((imageWidth * y) + x) * 4
let r = data[pixelIndex]
let g = data[pixelIndex + 1]
let b = data[pixelIndex + 2]
let a = data[pixelIndex + 3]
if a != 0 {
if r != 0 || g != 0 || b != 0 {
return false
}
}
}
}
return true
}
当我在独立的应用程序中使用此代码时,一切正常。
2019-10-25 19:17:56,835 [ 81159] ERROR - roject.impl.ProjectManagerImpl - From the listener com.homework.plugin.PluginTasksProjectComponent$1@1c0e28b2 (class com.homework.plugin.PluginTasksProjectComponent$1)
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$1.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();
}
}
对象创建所在的行抛出异常。
Jackson2ObjectMapperBuilder尝试将一些Kotlin模块转换为Module类,但我不明白为什么该代码块无法在独立应用程序中执行。
也许有人知道,问题的根源?
答案 0 :(得分:0)
问题解决了。我应该添加此依赖项
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.10.0</version>
</dependency>