title: Custom MessageConverter with Spring JmsMessagingTemplate is not working as I expected
body: <p>I'm trying to attach a custom message converter that implements <code>org.springframework.jms.support.converter.MessageConverter</code>, to a <code>JmsMessagingTemplate</code>. </p>
  
  <p>I've read somewhere that we can attach the message converter to a <code>MessagingMessageConverter</code> by calling <code>setPayloadConverter</code>, and then attach that messaging message converter to the <code>JmsMessagingTemplate</code> via <code>setJmsMessageConverter</code>. After that, I call <code>convertAndSend</code>, but I notice that it doesn't convert the payload. </p>
  
  <p>When I debugged the code, I notice that setting Jms Message Converter doesn't set the <code>converter</code> instance variable in the <code>JmsMessagingTemplate</code>. So when the <code>convertAndSend</code> method calls <code>doConvert</code> and tries to <code>getConverter</code>, it is getting the default simple message converter and not my custom one.</p>
  
  <p>My question is, can I use an implementation of <code>org.springframework.jms.support.converter.MessageConverter</code> with a <code>JmsMessagingTemplate</code>? Or do I need to use an implementation of <code>org.springframework.messaging.converter.MessageConverter</code>? </p>
  
  <p>I'm using Spring Boot 1.4.1.RELEASE, and Spring 4.3.3.RELEASE. The code is below.</p>
  
  <p><strong>Configuration</strong></p>
  
  <pre><code>@Configuration
  @EnableJms
  public class MessagingEncryptionPocConfig {
      /**
       * Listener ActiveMQ Connection Factory
       */
      @Bean(name="listenerActiveMqConnectionFactory")
      public ActiveMQConnectionFactory listenerActiveMqConnectionFactory() {
          return new ActiveMQConnectionFactory("admin","admin","tcp://localhost:61616");
      }
  
      /**
       * Producer ActiveMQ Connection Factory
       */
      @Bean(name="producerActiveMqConnectionFactory")
      public ActiveMQConnectionFactory producerActiveMqConnectionFactory() {
          return new ActiveMQConnectionFactory("admin","admin","tcp://localhost:61616");
      }   
  
      /**
       * Caching Connection Factory
       */
      @Bean
      public CachingConnectionFactory cachingConnectionFactory(@Qualifier("producerActiveMqConnectionFactory") ActiveMQConnectionFactory activeMqConnectionFactory) {
          return new CachingConnectionFactory(activeMqConnectionFactory);
      }
  
      /**
       * JMS Listener Container Factory
       */
      @Bean
      public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(@Qualifier("listenerActiveMqConnectionFactory") ActiveMQConnectionFactory connectionFactory, MessagingMessageConverter messageConverter) {
          DefaultJmsListenerContainerFactory defaultJmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
          defaultJmsListenerContainerFactory.setConnectionFactory(connectionFactory);
          defaultJmsListenerContainerFactory.setMessageConverter(messageConverter);
          return defaultJmsListenerContainerFactory;
      }
  
      /**
       * Jms Queue Template
       */
      @Bean(name="queueTemplate")
      public JmsMessagingTemplate queueTemplate(CachingConnectionFactory cachingConnectionFactory, MessageConverter messagingMessageConverter) {
          JmsMessagingTemplate queueTemplate = new JmsMessagingTemplate(cachingConnectionFactory);
          queueTemplate.setJmsMessageConverter(messagingMessageConverter);
          return queueTemplate;
      }
  
      @Bean
      public MessageConverter encryptionDecryptionMessagingConverter(Jaxb2Marshaller jaxb2Marshaller) {
          MessageConverter encryptionDecryptionMessagingConverter = new EncryptionDecryptionMessagingConverter(jaxb2Marshaller);
          MessagingMessageConverter messageConverter = new MessagingMessageConverter();
          messageConverter.setPayloadConverter(encryptionDecryptionMessagingConverter);
          return messageConverter;
      }
  
      /**
       * Jaxb marshaller
       */
      @Bean(name="producerJaxb2Marshaller")
      public Jaxb2Marshaller jaxb2Marshaller() {
          Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
          jaxb2Marshaller.setPackagesToScan("com.schema");
          return jaxb2Marshaller;
      }
  }
  </code></pre>
  
  <p><strong>MessageProducer Class</strong></p>
  
  <pre><code>@Component 
  public class MessageProducer {
  
      private static final Logger LOG = LoggerFactory.getLogger(MessageProducer.class);
  
      @Autowired
      @Qualifier("queueTemplate")
      private JmsMessagingTemplate queueTemplate;
  
      public void publishMsg(Transaction trx, Map&lt;String,Object&gt; jmsHeaders, MessagePostProcessor postProcessor) {
          LOG.info("Sending Message. Payload={} Headers={}",trx,jmsHeaders);
          queueTemplate.convertAndSend("queue.source", trx, jmsHeaders, postProcessor);
      }
  }
  </code></pre>
  
  <p><strong>Unit Test</strong></p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  @ActiveProfiles("test")
  public class WebsMessagingEncryptionPocApplicationTests {
      @Autowired
      private MessageProducer producer;
  
      @Autowired
      private MessageListener messageListener;    
  
      /**
       * Ensure that a message is sent, and received.
       */
      @Test
      public void testProducer() throws Exception{
          //ARRANGE
          CountDownLatch latch = new CountDownLatch(1);
          messageListener.setCountDownLatch(latch);
          Transaction trx = new Transaction();
          trx.setCustomerAccountID(new BigInteger("111111"));
          Map&lt;String,Object&gt; jmsHeaders = new HashMap&lt;String,Object&gt;();
          jmsHeaders.put("tid", "1234563423");
          MessagePostProcessor encryptPostProcessor = new EncryptMessagePostProcessor();
          //ACT
          producer.publishMsg(trx, jmsHeaders, encryptPostProcessor);
          latch.await();
          //ASSERT - assertion done in the consumer       
      }
  }
  </code></pre>