学习Spring框架时候的疑问

学习Spring 框架时,使用注解注入对象,为什么配置上@ PreDestroy注解,调用 ((ClassPathXmlApplicationContext)context).registerShutdownHook();方法,
IoC中的对象没有被销毁?
示意如下:

在这里插入图片描述


在这里插入图片描述


在这里插入图片描述


期望的销毁语句未执行?

在这里插入图片描述

registerShutdownHook 这里只是注册钩子程序, 并不会执行 @PreDestroy 注解标记的方法。 要等到 JVM关闭或者Spring自身关闭退出,才执行。

如下:

img

img


如有帮助,欢迎采纳哈!

在这里插入图片描述

本人的开源项目,欢迎star支持下!!!

在xml文件添加处理该注解的bean


    <bean id="org.springframework.context.annotation.internalCommonAnnotationProcessor" class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />