1

我刚刚将我的应用程序更新到版本spring-integration-amqp-5.2.4.RELEASE,当我从队列中收到消息时一切正常,但我注意到课堂上的警告java.lang.ClassNotFoundExceptionDefaultAmqpHeaderMapper我使用自定义DefaultJackson2JavaTypeMapperIdClassMapping. 如何避免跟踪警告?

@Bean
public Jackson2JavaTypeMapper defaultJackson2JavaTypeMapper() {
    DefaultJackson2JavaTypeMapper defaultJackson2JavaTypeMapper = new DefaultJackson2JavaTypeMapper();
    Map<String, Class<?>> classMapping = new HashMap<>();
    classMapping.put("event.request", RequestDTO.class);
    defaultJackson2JavaTypeMapper.setIdClassMapping(classMapping);
    return defaultJackson2JavaTypeMapper;
}

@Bean
public MessageConverter messageConverterJson(ObjectMapper objectMapper) {
    Jackson2JsonMessageConverter messageConverter = new Jackson2JsonMessageConverter(objectMapper);
    messageConverter.setJavaTypeMapper(defaultJackson2JavaTypeMapper());
    return messageConverter;
}

日志警告

o.s.i.a.support.DefaultAmqpHeaderMapper  : error occurred while mapping from AMQP properties to MessageHeaders

java.lang.IllegalStateException: java.lang.ClassNotFoundException: event.request
    at org.springframework.integration.mapping.support.JsonHeaders.getClassForValue(JsonHeaders.java:89)
    at org.springframework.integration.mapping.support.JsonHeaders.buildResolvableType(JsonHeaders.java:72)
    at org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper.createJsonResolvableTypHeaderInAny(DefaultAmqpHeaderMapper.java:169)
    at org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper.extractStandardHeaders(DefaultAmqpHeaderMapper.java:155)
    at org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper.extractStandardHeaders(DefaultAmqpHeaderMapper.java:61)
    at org.springframework.integration.mapping.AbstractHeaderMapper.toHeaders(AbstractHeaderMapper.java:266)
    at org.springframework.integration.mapping.AbstractHeaderMapper.toHeadersFromRequest(AbstractHeaderMapper.java:203)
    at org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper.toHeadersFromRequest(DefaultAmqpHeaderMapper.java:337)
    at org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper.toHeadersFromRequest(DefaultAmqpHeaderMapper.java:61)
    at org.springframework.integration.amqp.inbound.AmqpInboundGateway$Listener.convert(AmqpInboundGateway.java:351)
    at org.springframework.integration.amqp.inbound.AmqpInboundGateway$Listener.onMessage(AmqpInboundGateway.java:314)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1579)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1498)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1486)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1477)
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1421)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:963)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:913)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:81)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1284)
    at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1190)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: event.request
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.springframework.util.ClassUtils.forName(ClassUtils.java:282)
    at org.springframework.integration.mapping.support.JsonHeaders.getClassForValue(JsonHeaders.java:86)
    ... 21 common frames omitted
4

1 回答 1

1

由于您已经通过 将 AMQP 消息映射到目标有效负载Jackson2JsonMessageConverter,因此看起来您根本不需要任何传入标头。

为避免该警告和额外的映射工作,我建议您注入一个自定义AmqpHeaderMapper. DefaultAmqpHeaderMapper当您从请求返回一个空标头以进行映射时,可能只是对 , 的扩展:

amqpInboundGateway.setHeaderMapper(new DefaultAmqpHeaderMapper(null, null) {

        @Override
        public Map<String, Object> toHeadersFromRequest(MessageProperties source) {
            return new HashMap<>();
        }

    });

另一方面,它只是一个警告:您可以简单地将日志级别降低到该org.springframework.integration.amqp.inbound类别的错误。

关键是如果我们找不到__Type__标题的类,我们不能忽略这样的错误。该框架无法做出您期望的假设。

另一种可能的修复方法是在覆盖时从扩展中删除那些 JSONMessageProperties.getHeaders()Jackson2JsonMessageConverterfromMessage()

于 2020-03-16T16:45:10.883 回答