title: Spring scheduler shutdown error
body: <p>During development a SPRING based scheduler in a tomcat container, I always get this logoutput at undeploy webapp or shutdown server:</p>
  
  <pre><code>Apr 28, 2010 4:21:33 PM org.apache.catalina.core.StandardService stop
  INFO: Stopping service Catalina
  Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1] but has failed to stop it. This is very likely to create a memory leak.
  Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-2] but has failed to stop it. This is very likely to create a memory leak.
  Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-3] but has failed to stop it. This is very likely to create a memory leak.
  Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4] but has failed to stop it. This is very likely to create a memory leak.
  Apr 28, 2010 4:21:33 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  SEVERE: A web application appears to have started a thread named [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-5] but has failed to stop it. This is very likely to create a memory leak.
  .
  .
  .    
  SEVERE: A web application created a ThreadLocal with key of type [org.springframework.core.NamedThreadLocal] (value [Prototype beans currently in creation]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
  Apr 28, 2010 4:21:34 PM org.apache.coyote.http11.Http11Protocol destroy
  INFO: Stopping Coyote HTTP/1.1 on http-8606
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <p>thank you <a href="https://stackoverflow.com/users/116880/stevedbrown">stevedbrown</a></p>
  
  <p>I add this listener to my webapp</p>
  
  <pre><code>public class ShutDownHook implements ServletContextListener {
      @Override
      public void contextDestroyed(ServletContextEvent arg0) {
          BeanFactory bf = (BeanFactory) ContextLoader.getCurrentWebApplicationContext();
          if (bf instanceof ConfigurableApplicationContext) {
              ((ConfigurableApplicationContext)bf).close();
          }
      }
  
      @Override
      public void contextInitialized(ServletContextEvent arg0) {
      }
  }
  </code></pre>
  
  <p>and my web.xml</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;pkg.utility.spring.ShutDownHook&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>but the error is still there.</p>
  
  <p>spring config:</p>
  
  <p>
          
      </p>
  
  <pre><code>&lt;bean id="run" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;
      &lt;property name="concurrent" value="false" /&gt;
      &lt;property name="targetObject" ref="scheduler" /&gt;
      &lt;property name="targetMethod" value="task" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="cronTrg" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;
      &lt;property name="jobDetail" ref="run" /&gt;
      &lt;property name="cronExpression" value="0/5 * * * * ?" /&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" destroy-method="destroy"&gt;
      &lt;property name="triggers"&gt;
          &lt;list&gt;
              &lt;ref bean="cronTrg" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>