Skip to content
Advertisement

How to configure JmsMessagingTemplate to use MappingJackson2MessageConverter

I am looking at using JmsMessagingTemplate instead of JmsTemplate because I would like to use convertSendAndReceive. The messages should be send in JSON format. I am having difficulties convincing JmsMessagingTemplate to use MappingJackson2MessageConverter instead of the SimpleMessageConverter. The documentation seems to indicate that having a bean for MappingJackson2MessageConverter is enough to have it been used.

I created a small reproducing project. Given the following files:

JavaScript
JavaScript

I get the following exception:

JavaScript

Debugging the JmsMessagingTemplate I end up in AbstractMessageSendingTemplate where the message converter is of type SimpleMessageConverter in stead of the expected MappingJackson2MessageConverter.

I hope someone can show me the missing configuration or relevant docs.

Advertisement

Answer

You’re not setting the MessageConverter to the jmsMessagingTemplate bean that you’re using. You need to set the message converter using setJmsMessageConverter() method before calling convertSendAndReceive().

Here’s the javadocs – https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jms/core/JmsMessagingTemplate.html#setJmsMessageConverter-org.springframework.jms.support.converter.MessageConverter-

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement