不太理解什么时候是算Spring容器关闭了 :看下面这个例子:
定义一个bean:
<bean id="logBeforeAdvice"
                class="onlyfun.caterpillar.LogBeforeAdvice" init-method="initBean"
                destroy-method="destroyBean"/>      
public class LogBeforeAdvice{
    void initBean(){
        System.out.println("Start.....");
    }
    void destroyBean(){
        System.out.println("end.....");
    }
}测试它,看看bean的生命周期
public class SpringTest extends TestCase{
    publuc testBeanlife(){
        ApplicationContext context = new ClassPathXmlApplicationContext("beans-config.xml");
        context.getBean("logBeforeAdvice");
    }
}
---------------------------------------------------------------------需要调用ClassPathXmlApplicationContext.close()方法才可以关闭 ----------------------------------------------------------------------ClassPathXmlApplicationContext并没有close()这个静态方法。
我知道答案了:
在非Web应用程序中,若要在关闭容器前调用destroy的话,必须采用AbstractApplicationContext来处理,
publuc testBeanlife(){
        AbstractApplicationContext context = new ClassPathXmlApplicationContext("beans-config.xml");       context.registerShutdownHook();        context.getBean("logBeforeAdvice");
    }
}