相关文章推荐
跑龙套的开水瓶  ·  ComponentScan.Filter ...·  7 月前    · 
傻傻的馒头  ·  利用Pycharm + ...·  8 月前    · 
文武双全的蚂蚁  ·  MultipartReader.ReadNe ...·  1 年前    · 
英俊的啤酒  ·  android测试与调试 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

If it's not one problem , it's another ... I seem to have gotten the 2 previous problems fixed but now when running outside of a test context, with a stood up application I see this.

o.s.a.s.c.Jackson2JsonMessageConverter   : Could not convert incoming message with content-type [null], 'json' keyword missing.

Like before, this message seems fairly clear. Heck, things even worked in a standalone test context, however when running in a standalone server the code seems to be taking a different path and is failing for the same reason but via a different component.

@Configuration
open class MessagingConfig {
    @Bean
    open fun jackson2Json(om: ObjectMapper): SmartMessageConverter {
        return Jackson2JsonMessageConverter(om)
    @Bean
    open fun mappingJackson2(om: ObjectMapper): MappingJackson2MessageConverter {
        val mc = MappingJackson2MessageConverter()
        mc.objectMapper = om
        return mc
    @Bean
    open fun defaultMessageHandlerMethodFactory(jackson: MappingJackson2MessageConverter): DefaultMessageHandlerMethodFactory {
        val factory = DefaultMessageHandlerMethodFactory()
        factory.setMessageConverter(jackson)
        return factory
    @Bean
    open fun builder(): Jackson2ObjectMapperBuilderCustomizer {
        return Jackson2ObjectMapperBuilderCustomizer {
            it.modules(JavaTimeModule(), KotlinModule())
            it.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
    @Configuration
    open class RabbitConfigurer(val dmhmf: DefaultMessageHandlerMethodFactory) : RabbitListenerConfigurer {
        override fun configureRabbitListeners(registrar: RabbitListenerEndpointRegistrar?) {
            registrar?.messageHandlerMethodFactory = dmhmf

You can add a MessagePostprocessor to the container factory to enhance the message with a content_id property.

factory.setAfterReceivePostProcessors(m -> {
    m.getMessageProperties().setContentId("application/json");
    return m;
                which factory? I take it that it's different from the one I'm creating now as it doesn't have that method
– xenoterracide
                Mar 12, 2019 at 17:52
                SimpleRabbitListenerContainerFactory or DirectRabbitListenerContainerFactory depending on your container type.
– Gary Russell
                Mar 12, 2019 at 18:06

According the logic in the AbstractJackson2MessageConverter, the contentType AMQP property is required:

MessageProperties properties = message.getMessageProperties();
    if (properties != null) {
        String contentType = properties.getContentType();
        if (contentType != null && contentType.contains(this.supportedContentType.getSubtype())) {

I think we need to bring an improvement into this component do not be strict with it. The same way as we can do with the MappingJackson2MessageConverter via its:

* Whether this converter should convert messages for which no content type * could be resolved through the configured * {@link org.springframework.messaging.converter.ContentTypeResolver}. * <p>A converter can configured to be strict only when a * {@link #setContentTypeResolver contentTypeResolver} is configured and the * list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty. * <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)} * will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver} * is not defined or if no content-type header is present. public void setStrictContentTypeMatch(boolean strictContentTypeMatch) {

which is false by default.

Only the way to overcome the issue with missed contentType, but still proceed with the JSON message conversion, I see with a custom org.springframework.amqp.support.converter.AbstractMessageConverter implementation where you can combine a Jackson2JsonMessageConverter logic and don't care about missed contentType property.

Feel free to raise an issue against Spring AMQP to improve an AbstractJackson2MessageConverter!

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.