title: Setup of JMS message listener invoker failed for destination trying to recover
body: <p>While running integration tests in my application, I get below error messages in the failsafe test report for one of my integration test:  </p>
  
  <pre><code>listener.DefaultMessageListenerContainer,WARN,Setup of JMS message listener invoker failed for destination 'jms/myapp.OneWorker' - trying to recover. Cause: Destination [jms/myapp.OneWorker] not found in JNDI; nested exception is javax.naming.NameNotFoundException: jms/myapp.OneWorker
  </code></pre>
  
  <p>Below is my configuration detail:
  </p>
  
  <pre><code>&lt;bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"&gt;
      &lt;property name="environment"&gt;
          &lt;props&gt;
              &lt;prop key="java.naming.factory.initial"&gt;
                  org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/prop&gt;
              &lt;prop key="java.naming.provider.url"&gt;vm://localhost:0&lt;/prop&gt;
              &lt;prop key="java.naming.security.principal"&gt;system&lt;/prop&gt;
              &lt;prop key="java.naming.security.credentials"&gt;system&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jndiQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiTemplate" ref="jndiTemplate" /&gt;
      &lt;property name="jndiName" value="jmsFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="queueConnectionFactory"
      class="org.springframework.jms.connection.CachingConnectionFactory"&gt;
      &lt;property name="targetConnectionFactory" ref="jndiQueueConnectionFactory" /&gt;
      &lt;property name="sessionCacheSize" value="1" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="destinationResolver"
      class="org.springframework.jms.support.destination.JndiDestinationResolver"&gt;
      &lt;property name="jndiTemplate" ref="jndiTemplate" /&gt;
      &lt;property name="cache" value="true" /&gt;
      &lt;property name="fallbackToDynamicDestination" value="false" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
      &lt;property name="connectionFactory" ref="queueConnectionFactory" /&gt;
      &lt;property name="destinationResolver" ref="destinationResolver" /&gt;
      &lt;property name="pubSubDomain" value="true" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="workerOneListener" class="com.org.myapp.workflow.WorkerOne"&gt;
      &lt;property name="workflowManager" ref="workflowManagerImpl" /&gt;
  &lt;/bean&gt;
  
  &lt;jms:listener-container connection-factory="queueConnectionFactory"
      destination-resolver="destinationResolver" concurrency="3"&gt;
      &lt;jms:listener destination="jms/myapp.OneWorker" ref="workerOneListener" /&gt;
      &lt;jms:listener destination="jms/myapp.TwoWorker" ref="workerOneListener" /&gt;
      &lt;jms:listener destination="jms/myapp.ThreeWorker" ref="workerOneListener" /&gt;
  &lt;/jms:listener-container&gt;  
  </code></pre>
  
  <p>The integration tests have a base class which creates the spring application contexts and is shared by all the other integration tests in the module.<br>
  I enabled logging with debug level and got below error messages:  </p>
  
  <pre><code>2014-01-29 11:13:24,connection.CachingConnectionFactory,DEBUG,Closing cached Session:     ActiveMQSession {id=ID:CHN03876623-56121-1390973978321-2:0:70,started=true}
  2014-01-29 11:13:24,connection.CachingConnectionFactory,DEBUG,Closing cached Session: ActiveMQSession {id=ID:CHN03876623-56121-1390973978321-2:0:70,started=true}
  2014-01-29 11:13:24,connection.CachingConnectionFactory,DEBUG,Creating cached JMS Session for mode 1: ActiveMQSession {id=ID:CHN03876623-56121-1390973978321-2:0:71,started=true}
  2014-01-29 11:13:24,jndi.JndiTemplate,DEBUG,Looking up JNDI object with name [jms/myapp.OneWorker]
  2014-01-29 11:13:24,destination.JndiDestinationResolver,DEBUG,Destination [jms/myapp.OneWorker] not found in JNDI
  javax.naming.NameNotFoundException: jms/myapp.OneWorker
      at org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:225)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
      at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
      at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
      at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
      at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
      at org.springframework.jms.support.destination.JndiDestinationResolver.resolveDestinationName(JndiDestinationResolver.java:111)
      at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:100)
      at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:221)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1081)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
      at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>This log message is repeated again and again infinitely and for the other two workers also. And the build hangs at this point. I use <code>unitils</code> framework for integration testing and create spring context using <code>@SpringApplicationContext</code> in my base integration test class. Where am I going wrong?</p>