学习Spring 框架时,使用注解注入对象,为什么配置上@ PreDestroy注解,调用 ((ClassPathXmlApplicationContext)context).registerShutdownHook();方法,
IoC中的对象没有被销毁?
示意如下:
registerShutdownHook 这里只是注册钩子程序, 并不会执行 @PreDestroy 注解标记的方法。 要等到 JVM关闭或者Spring自身关闭退出,才执行。
如下:
如有帮助,欢迎采纳哈!
在xml文件添加处理该注解的bean
<bean id="org.springframework.context.annotation.internalCommonAnnotationProcessor" class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />