Announcement Announcement Module
Collapse
No announcement yet.
destroy-method not called Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • destroy-method not called

    I am having a problem getting the method specified by the "destroy-method" attribute to be called when the application context is destroyed. My bean config file is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <bean id="testbean" class="com.test.TestBean" destroy-method="cleanup" singleton="true" />
    </beans>

    To make sure that my application context was destroyed I:

    1. retrieved the WebApplicationContext cached in the ServletContext
    2. cast it to a ConfigurableApplicationContext
    3. called close()

    This is not cause the destroy-method to fire. Has anyone encountered this problem.

    rzeng

  • #2
    Are you sure you have a cleanup() method without arguments. Is it public? I just created a simple test:

    Code:
    public class BlaTest extends TestCase &#123;
    	
    	public void testBla&#40;&#41; &#123;
    		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext&#40;"/nl/ilse/statistics/blaContext.xml"&#41;;
    		ctx.close&#40;&#41;;		
    		assertTrue&#40;BlaBean.closeCalled&#41;;		
    	&#125;
    &#125;
    Code:
    public class BlaBean &#123;
    	
    	public static boolean closeCalled = false;
    	
    	public void close&#40;&#41; &#123;
    		closeCalled = true;
    	&#125;
    &#125;
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean class="nl.ilse.statistics.BlaBean" destroy-method="close"/>
    </beans>
    And this works...

    regards,

    Alef

    Comment

    Working...
    X