使用 rocketmq,消费消息报错
Describe the bug
消费消息的时候,会遇到jackson转化类型错误
2021-02-04 22:21:52.515 ERROR 71659 --- [MessageThread_1] .a.c.s.b.r.s.JacksonRocketMQHeaderMapper : Could not decode json type: {"type":"application","subtype":"json","parameters":{},"concrete":true,"wildcardType":false,"wildcardSubtype":false,"charset":null} for key: accept
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `org.springframework.util.MimeType` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"type":"application","subtype":"json","parameters":{},"concrete":true,"wildcardType":false,"wildcardSubtype":false,"charset":null}"; line: 1, column: 2]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1588) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1213) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1400) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:362) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:195) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4593) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3548) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3516) ~[jackson-databind-2.12.1.jar:2.12.1]
at com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper.decodeValue(JacksonRocketMQHeaderMapper.java:191) ~[spring-cloud-starter-stream-rocketmq-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper.lambda$toHeaders$1(JacksonRocketMQHeaderMapper.java:128) ~[spring-cloud-starter-stream-rocketmq-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at java.util.HashMap.forEach(HashMap.java:1336) ~[?:?]
at com.alibaba.cloud.stream.binder.rocketmq.support.JacksonRocketMQHeaderMapper.toHeaders(JacksonRocketMQHeaderMapper.java:111) ~[spring-cloud-starter-stream-rocketmq-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer.convertToSpringMessage(RocketMQListenerBindingContainer.java:406) ~[spring-cloud-starter-stream-rocketmq-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer.access$100(RocketMQListenerBindingContainer.java:71) ~[spring-cloud-starter-stream-rocketmq-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.alibaba.cloud.stream.binder.rocketmq.consuming.RocketMQListenerBindingContainer$DefaultMessageListenerConcurrently.consumeMessage(RocketMQListenerBindingContainer.java:420) ~[spring-cloud-starter-stream-rocketmq-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService$ConsumeRequest.run(ConsumeMessageConcurrentlyService.java:417) ~[rocketmq-client-4.4.0.jar:4.4.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
spring boot 版本 2.3.2
spring cloud 版本 Hoxton.SR8
jdk 11
spring-cloud-starter-stream-rocketmq 版本 2.2.5.RELEASE
macOS 11.2
一开始以为是jackson版本问题,从2.10.5,改为2.12.1,结果错误还是一样。
最后把spring boot 版本升级为2.3.8结果还是一样类型转换错误,同样的错误。
找到那个 MimeType java文件,没有发现默认构造函数,应该是这个导致的错误🙂
2条答案
按热度按时间jfgube3f1#
org.springframework.util.MimeType 这个文件复写下,加上 @AllArgsConstructor 和 @NoArgsConstructor 就好了。。
slhcrj9b2#
I also encountered this problem. Is there a solution?