Note that there are some explanatory texts on larger screens.

plurals
  1. POLazy init not honored for JmsTemplate
    primarykey
    data
    text
    <p>We are developing a Spring-based application that utilizes JMSTemplate to send/receive JMS messages to/from the Tibco EMS Server.</p> <p>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. </p> <p>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. </p> <h3>An excerpt:</h3> <pre><code>&lt;bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager" lazy-init="true"&gt; &lt;property name="internalJmsQueueConnectionFactory"&gt; &lt;ref bean="jmsQueueConnectionFactory" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="jmsTemplateWithClientAcknowledge" class="org.springframework.jms.core.JmsTemplate" lazy-init="true"&gt; &lt;property name="internalJmsQueueConnectionFactory" ref="jmsQueueConnectionFactory"/&gt; &lt;/bean&gt; </code></pre> <p>Here's the problem: if we set <code>lazy-init="true"</code> ONLY on <em>jmsTransactionManager</em> bean, the project loads fine without problems. However, as soon as we set <code>lazy-init="true"</code> on the <em>jmsTemplateWithClientAcknowledge</em> bean as well, the project fails. Same failure reason: <strong><em>couldn't connect to the EMS Server</em></strong>.</p> <h3>The error from the log:</h3> <blockquote> <p>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]</p> </blockquote> <p>I will greatly appreciate your thoughts and help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload