title: NoClassDefFoundError on org.springframework.jms.listener.DefaultMessageListenerContainer during Tomcat restart
body: <p>Our application has a listener that consumes messages from ActiveMQ broker. However, in the production environment, we have added script to restart the Tomcat server daily. Following is the script that restart the tomcat SERVICE in the production server;</p>
  
  <pre><code>date /t &gt;&gt; Restart_Production_Tomcats.log
  time /t &gt;&gt; Restart_Production_Tomcats.log
  echo "Restart Tomcat Production Server" &gt;&gt; Restart_Production_Tomcats.log
  net stop "Application1" &gt;&gt; Restart_Production_Tomcats.log timeout /T 60 /NOBREAK
  net start "Application1" &gt;&gt; Restart_Production_Tomcats.log
  time /t &gt;&gt; Restart_Production_Tomcats.log
  echo "Restart_Production_Tomcats completed" &gt;&gt; Restart_Production_Tomcats.log 
  echo "" &gt;&gt; Restart_Production_Tomcats.log 
  </code></pre>
  
  <p>Normally, during the restart, log file get following exception one time at each restart;</p>
  
  <pre><code>Exception in thread "org.springframework.jms.listener.DefaultMessageListenerContainer#0-3834" java.lang.NoClassDefFoundError: org/springframework/jms/connection/SmartConnectionFactory 
  at org.springframework.jms.connection.ConnectionFactoryUtils.releaseConnection(ConnectionFactoryUtils.java:71) 
  at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:386) 
  at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:869) 
  at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:851) 
  at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:982) 
  at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>However, one particular day I got more than <strong>3000</strong> such exceptions, on that days even Tomcat couldn't restart properly. <em>For me, it seems like JVM classloader can not find 
  <code>org.springframework.jms.listener.DefaultMessageListenerContainer</code> class during the restart</em>. </p>
  
  <p>Can someone please explain what is happening when restarting tomcat and why I got this exception? However, in our development environment I can not replicate this issue or even we can not see this issue in other production environment. Is it due to restart the Tomcat server while processing messages from the ActiveMQ by listener? or some issue with restart script?</p>
  
  <p>I found similar question, <a href="https://stackoverflow.com/questions/2014465/noclassdeffounderror-in-spring">NoClassDefFoundError in spring</a> However, I couldn't find clear answer for my question with this question.</p>