gpt4 book ai didi

spring-boot - org.springframework.messaging.converter.MessageConversionException异常

转载 作者:行者123 更新时间:2023-12-05 06:22:39 27 4
gpt4 key购买 nike

使用 Avro 消息格式。

低于异常。反序列化后无法映射到 AvroPlanCompleteTrigger java 对象。有人可以帮忙吗?

Bean [com.wom.repl.odr.receiver.Receiver@606b1c65]; nested exception is org.springframework.messaging.converter.MessageConversionException: Cannot handle message; nested exception is org.springframework.messaging.converter.MessageConversionException: Cannot convert from [com.wom.repl.odr.dto.AvroPlanCompleteTrigger] to [com.wom.repl.odr.dto.AvroPlanCompleteTrigger] for GenericMessage [payload={"groupId": 609001, "runUUID": "runuuid", "wmtItemNumber": "123456", "sourceLocation": 987, "retryCount": 3, "applicationName": "Jenkins"}, headers={kafka_offset=0, kafka_receivedMessageKey=null, kafka_receivedPartitionId=0, kafka_receivedTopic=test3, kafka_acknowledgment=Acknowledgment for ConsumerRecord(topic = test3, partition = 0, offset = 0, CreateTime = 1574768943315, checksum = 2886880703, serialized key size = -1, serialized value size = 29, key = null, value = {"groupId": 1234, "runUUID": "runuuid", "wmtItemNumber": "123456", "sourceLocation": 987, "retryCount": 3, "applicationName": "Jenkins"})}], failedMessage=GenericMessage [payload={"groupId": 1234, "runUUID": "runuuid", "wmtItemNumber": "123456", "sourceLocation": 987, "retryCount": 3, "applicationName": "Jenkins"}, headers={kafka_offset=0, kafka_receivedMessageKey=null, kafka_receivedPartitionId=0, kafka_receivedTopic=test3, kafka_acknowledgment=Acknowledgment for ConsumerRecord(topic = test3, partition = 0, offset = 0, CreateTime = 1574768943315, checksum = 2886880703, serialized key size = -1, serialized value size = 29, key = null, value = {"groupId": 609001, "runUUID": "runuuid", "wmtItemNumber": "123456", "sourceLocation": 987, "retryCount": 3, "applicationName": "Jenkins"})}], at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:178), at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:72), at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:47), at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:794), at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:738), at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.access$2200(KafkaMessageListenerContainer.java:245), at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer$ListenerInvoker.run(KafkaMessageListenerContainer.java:1031), at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511), at java.util.concurrent.FutureTask.run(FutureTask.java:266), at java.lang.Thread.run(Thread.java:748)] :END

Pom 依赖版本:

<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>1.9.1</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

我使用下面的 AvroDeserializer 方法获取 AvroPlanCompleteTrigger 这个 java 对象。


public T deserialize(String topic, byte[] data) {
try {
T result = null;

if (data != null) {
LOGGER.debug("data='{}'", DatatypeConverter.printHexBinary(data));

DatumReader<GenericRecord> datumReader = new SpecificDatumReader<>(
targetType.newInstance().getSchema());
Decoder decoder = DecoderFactory.get().binaryDecoder(data, null);

result = (T) datumReader.read(null, decoder);
LOGGER.debug("deserialized data='{}'", result);
}
return result;
} catch (Exception ex) {
throw new SerializationException(
"Can't deserialize data '" + Arrays.toString(data) + "' from topic '" + topic + "'", ex);
}
}

最佳答案

看起来你已经反序列化了一个 com.wom.replenishment.odr.dto.AvroPlanCompleteTrigger 但方法参数是一个 com.wom.repl.odr.dto.AvroPlanCompleteTrigger.

Spring 不知道如何从一个转换为另一个。

关于spring-boot - org.springframework.messaging.converter.MessageConversionException异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59052941/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com