1
votes

We are developing a Spring-based application that utilizes JMSTemplate to send/receive JMS messages to/from the Tibco EMS Server.

With the current implementation, during the TomCat start up the project fails if the EMS Server is down. This is because in the Spring config file, we have JMS related beans that are trying to connect to the EMS server.

So, one solution is to make all JMS related beans initiate only when they are required (and not during the start up). For that we set all the JMS related beans' lazy-init attribute to true.

An excerpt:

<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager" lazy-init="true">
    <property name="internalJmsQueueConnectionFactory"> <ref bean="jmsQueueConnectionFactory" />
    </property>
</bean>

<bean id="jmsTemplateWithClientAcknowledge" class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
    <property name="internalJmsQueueConnectionFactory" ref="jmsQueueConnectionFactory"/>
</bean>

Here's the problem: if we set lazy-init="true" ONLY on jmsTransactionManager bean, the project loads fine without problems. However, as soon as we set lazy-init="true" on the jmsTemplateWithClientAcknowledge bean as well, the project fails. Same failure reason: couldn't connect to the EMS Server.

The error from the log:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsMsgSenderImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jms.core.JmsTemplate com.cv.pub.engine.service.impl.JmsMsgSenderImpl.jmsTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplateWithClientAcknowledge' defined in ServletContext resource [/WEB-INF/spring/jms-context.xml]: Cannot resolve reference to bean 'internalJmsQueueConnectionFactory' while setting bean property 'connectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'internalJmsQueueConnectionFactory' defined in ServletContext resource [/WEB-INF/spring/jms-context.xml]: Cannot resolve reference to bean 'targetJmsQueueConnectionFactory' while setting bean property 'targetConnectionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'targetJmsQueueConnectionFactory' defined in ServletContext resource [/WEB-INF/spring/jms-context.xml]: Invocation of init method failed; nested exception is javax.naming.ServiceUnavailableException: Failed to query JNDI: Failed to connect to the server at tcp://localhost:7222 [Root exception is javax.jms.JMSException: Failed to connect to the server at tcp://localhost:7222]

I will greatly appreciate your thoughts and help!

1
We'll need to see the bean definition for jmsQueueConnectionFactory alsoskaffman

1 Answers

0
votes

Is targetJmsQueueConnectionFactory being used by internalJmsQueueConnectionFactory? According to the log it appears to be like that. You will need to make internalJmsQueueConnectionFactory also lazy-init.