title: destroy-method of spring bean is not getting called when my tomcat shuts down
body: <p>I am not able to find the cause why my <code>destroy-method</code> is not getting called when my application gets shut down in case of the tomcat stops.</p>
  
  <p>I have a web application and the spring context is getting loaded through ContextLoaderListener in web.xml like below:</p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;classpath:appContext.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>below is a Employee bean in my application:</p>
  
  <p><strong>Employee.class</strong></p>
  
  <pre><code>public class Employee {
      String eName;
      long eSal;
      public String getEName() {
          return eName;
      }
      public void setEName(String name) {
          eName = name;
      }
      public long getESal() {
          return eSal;
      }
      public void setESal(long sal) {
          eSal = sal;
      }
  
      public void init() {
          System.out.println("Initiaizing...");
          System.out.println("eName: " + eName + " - eSal: " + eSal);
      }
  
      public void close() {
          System.out.println("Destroying...");
      }
  }
  </code></pre>
  
  <p>and the bean is defined in my application context file like below:</p>
  
  <p><strong>appContext.xml</strong></p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/integration"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
      &lt;beans:bean id="employee" class="com.test.Employee" init-method="init" destroy-method="close"&gt;
          &lt;beans:property name="eName" value="sandip" /&gt;
          &lt;beans:property name="eSal" value="80000" /&gt;
      &lt;/beans:bean&gt;        
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>Tomcat console logs:</p>
  
  <pre><code>May 12, 2014 11:28:46 AM org.apache.catalina.core.AprLifecycleListener init
  INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jre7\bin\client;C:\Program Files\Java\jre7\bin;C:\Program Files\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Lenovo\Access Connections\;D:\Project\maven-2.0.7\bin;D:\Software Backup\apache-ant-1.7.0\bin;C:\Program Files\Java\jdk1.6.0_20\bin;D:\Project\OBD3\1.5;D:\Software Backup\CVS;D:\Project\UNIX\UnxUtils\usr\local\wbin;C:\Program Files\QuickTime\QTSystem\;D:\Personal\MongoDB\MongoDB_work\mongodb\bin;D:\Software Installed\MariaDB 5.5\bin;C:\Program Files\Git\bin
  May 12, 2014 11:28:46 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
  WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:testSpringBeanDestroy' did not find a matching property.
  May 12, 2014 11:28:46 AM org.apache.coyote.http11.Http11Protocol init
  INFO: Initializing Coyote HTTP/1.1 on http-8093
  May 12, 2014 11:28:46 AM org.apache.catalina.startup.Catalina load
  INFO: Initialization processed in 419 ms
  May 12, 2014 11:28:46 AM org.apache.catalina.core.StandardService start
  INFO: Starting service Catalina
  May 12, 2014 11:28:46 AM org.apache.catalina.core.StandardEngine start
  INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
  May 12, 2014 11:28:46 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
  INFO: validateJarFile(D:\Project\Workspace_new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\testSpringBeanDestroy\WEB-INF\lib\servlet.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
  May 12, 2014 11:28:46 AM org.apache.catalina.core.ApplicationContext log
  INFO: Initializing Spring root WebApplicationContext
  log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
  log4j:WARN Please initialize the log4j system properly.
  Initiaizing...
  eName: sandip - eSal: 80000
  May 12, 2014 11:28:47 AM org.apache.coyote.http11.Http11Protocol start
  INFO: Starting Coyote HTTP/1.1 on http-8093
  May 12, 2014 11:28:47 AM org.apache.jk.common.ChannelSocket init
  INFO: JK: ajp13 listening on /0.0.0.0:8011
  May 12, 2014 11:28:47 AM org.apache.jk.server.JkMain start
  INFO: Jk running ID=0 time=0/20  config=null
  May 12, 2014 11:28:47 AM org.apache.catalina.startup.Catalina start
  INFO: Server startup in 768 ms
  </code></pre>
  
  <p>When I start my tomcat I can see that my init method is getting called but unfortunately when I stops the tomcat the close() i.e. the destroy method is not getting called.</p>
  
  <p>I am using spring 3.1.2 distributions jars.</p>
  
  <p>What am I doing wrong?</p>