I am using JNDI lookup for the getting the connection object for Websphere MQ Broker on tomcat server. I am using JmsTemplate for sending the messages to the Queue on WMQ Broker and trying to avoid the Spring Xml based configuration and for that reason i have configured the Spring boot's application.properties file to specify the JNDI look up name.below is the property from application.properties file.
spring.jms.jndi-name= java:comp/env/XXXX
i am using a Spring bean to define the JmsTemplate and below is the code for it.
@Configuration
public class JmsMessageTemplateBean {
//@Value("${spring.jms.jndi-name}")
//private ConnectionFactory connectionFactory;
@Bean
public JmsTemplate jmsTemplate() throws Exception{
JmsTemplate jmsMessagingTemplate = new JmsTemplate();
jmsMessagingTemplate.setDefaultDestinationName("Some Queue");
jmsMessagingTemplate.setConnectionFactory(connectionFactory);
return jmsMessagingTemplate;
}
}
i have a couple of questions:
1.How to read the JNDI property from application.properties file and set the Connection object to Jms Template in the above bean.
2.I have observed that the connection object from the JNDI lookup is MQQueueConnectionFactory and from what i have researched JmsTemplate supports javax.jms.ConnectionFactory object. is there a way to convert the MQQueueConnectionfactory object to javax.jms.Connectionfactory.
Appreciate your answers.
JmsTemplatewith Spring Boots auto configuration. TheMQQueueConnectionFactoryis aConnectionFactory. - M. Deinum