I am trying to do a simple WAS/Spring/JMS application. I am grabbing the connection factory and the destination for JMS from WAS using JNDI. I am trying to use these objects with Spring JMS but I can't seem to get the casting correct. I have tried casting the connection factory to javax.jms.ConnectionFactory
and javax.jms.QueueConnectionFactory
. Should I be using some type of Spring connection factory? Any help is appreciated. WAS 8.5 and Spring 4.2.4.RELEASE.
@Bean
public ConnectionFactory jndiConnectionFactory() throws NamingException {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiName("jms/qcfBindingsXa");
jndiObjectFactoryBean.setLookupOnStartup(true);
jndiObjectFactoryBean.setCache(true);
jndiObjectFactoryBean.setResourceRef(true);
jndiObjectFactoryBean.setProxyInterface(javax.jms.ConnectionFactory.class);
jndiObjectFactoryBean.afterPropertiesSet();
return (ConnectionFactory) jndiObjectFactoryBean.getObject();
}
@Bean
public Destination destination() throws NamingException {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiName("jms/app/insertQ");
jndiObjectFactoryBean.setLookupOnStartup(true);
jndiObjectFactoryBean.setCache(true);
jndiObjectFactoryBean.setResourceRef(true);
jndiObjectFactoryBean.setProxyInterface(javax.jms.Destination.class);
jndiObjectFactoryBean.afterPropertiesSet();
return (Destination) jndiObjectFactoryBean.getObject();
}
@Bean
public DefaultMessageListenerContainer messageListenerContainter() throws NamingException{
DefaultMessageListenerContainer messageListenerContainter = new DefaultMessageListenerContainer();
messageListenerContainter.setDestination(destination());
messageListenerContainter.setConnectionFactory(jndiConnectionFactory());
//messageListenerContainter.setMessageConverter(messageConverter());
messageListenerContainter.setMessageListener(messageListener());
messageListenerContainter.setSessionTransacted(true);
messageListenerContainter.setDestinationResolver(destinationResolver());
messageListenerContainter.afterPropertiesSet();
return messageListenerContainter;
}
Error:
2016-02-12 09:51:03,493 ERROR o.s.j.l.DefaultMessageListenerContainer - Could not refresh JMS Connection for destination 'queue:///APP.INPUT.OC' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: AOP configuration seems to be invalid: tried calling method [public abstract javax.jms.Connection javax.jms.ConnectionFactory.createConnection() throws javax.jms.JMSException] on target
[com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle@18fbbd2_
managed connection factory = com.ibm.ejs.jms.WMQJMSRAManagedConnectionFactory@c51fdbc4_
connection manager = com.ibm.ejs.j2c.ConnectionManager@199d9f8f_
restricted methods enabled = false];
nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class +[]
Figured it out. Man do I feel stupid. :/ Had the javax.jms
jar both on the server class path as well as the application class path. Spring was looking at the application jar and WAS was looking at the server jar. I do not control or can see what is on the Server class path so I didn't realize the duplication. Thanks to everyone who at least read the question.