1.Bean销毁是发送在Spring容器关闭过程中的
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);UserService userService = (UserService) context.getBean("userService");userService.test();// 容器关闭context.close();
2.在Bean创建过程中,在最后(初始化之后),有一个步骤会去判断当前创建的Bean是不是DisposableBean:
public interface DisposableBean {void destroy() throws Exception;}
close方法:
@perDestroy