spring 我的init-method 方法执行了 但destroy-method没有执行

@PreDestory 注解的方法也没有执行

因为bean的生命周期没到,可以试着关闭IOC容器,这样bean就会被销毁,destroy-method会被执行:
AbstractApplicationContext cxt=new ClassPathXmlApplicationContext"beans.xml");
.........................................................................
cxt.registerShutdownHook();

以上例子可以看到bean被销毁,执行destroy method.
个人见解。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-02-05
因为bean的生命周期没到,可以试着关闭IOC容器,这样bean就会被销毁,destroy-method会被执行:
AbstractApplicationContext cxt=new ClassPathXmlApplicationContext"beans.xml");
.........................................................................
cxt.registerShutdownHook();

以上例子可以看到bean被销毁,执行destroy method.
第2个回答  2011-11-24
不明白你得意思,建议吧程序贴出来