美文网首页
Day 61 Spring Bean 生命周期

Day 61 Spring Bean 生命周期

作者: 小周爱吃瓜 | 来源:发表于2022-07-01 11:03 被阅读0次

实例化前->推断构造方法

Screen Shot 2022-07-01 at 9.33.27 AM.png Screen Shot 2022-07-01 at 9.45.44 AM.png
  1. 关于AutoWired Resource Value注解也是通过

postProcessProperties 这个后置处理来实现的.

  1. Aop也是基于初始化后实现的.

  • 关于BeanDefinition的描述
image.png
  • Disposable AutoCloseable ,destroyMethodName
    三种入参,但是出参只有一个,所以需要用到适配器模式.
@Configuration
public class BeanDestoryAdapter implements DisposableBean,Runnable {

    private Bean bean;

    public BeanDestoryAdapter(Bean bean) {
        //传递Bean 进来,有三种Bean销毁的方式
        //入参三种,销毁只有一种
        this.bean = bean;
    }

    @Override
    public void run() {

    }

    @Override
    public void destroy() throws Exception {
        DisposableBean disposableBean = (DisposableBean) bean;
        disposableBean.destroy();

        //有destory方法 或者 xxx接口的Bean

        //determineDestroyMethod
    }
}
  • 这个就是典型的适配器模式. (注意理解这个思想)

将实现了DisposableBean接口,AutoCloseable,或者标记@PreDestroy注解的方法通过Adapter做适配。

  • close方法
    ContextClosedEvent事件

DisposableBean 下 Destory ,可能还有相互关联的bean,inner beans,也会从单例池中进行移除.

相关文章

网友评论

      本文标题:Day 61 Spring Bean 生命周期

      本文链接:https://www.haomeiwen.com/subject/jxpavrtx.html