SpringBean的生命周期 (流程图)

Spring的生命周期示意图

在百度Spring的生命周期时,看到一篇不错的文章http://www.cnblogs.com/zrtqsk/p/3735273.html,但在仔细阅读源码后,发现作者有些地方笔误:

在这里插入图片描述在这里插入图片描述

源码

一.实例化BeanFactoryProcessor实现类
二.执行BeanFactoryProcessor的PostProcessFactory方法
在这里插入图片描述
三.实例化BeanPostProcessor实现类
在这里插入图片描述
四.实例化InstantiationAwareBeanPostProcessorAdapt实现类

public abstract class InstantiationAwareBeanPostProcessorAdapter implements SmartInstantiationAwareBeanPostProcessor {
    public InstantiationAwareBeanPostProcessorAdapter() {
    }

    @Nullable
    public Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {
        return null;
    }

    @Nullable
    public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
        return null;
    }

    public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Nullable
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        return null;
    }

    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        return true;
    }

    public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException {
        return null;
    }

    /** @deprecated */
    @Deprecated
    public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
        return pvs;
    }

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}

五.执行InstantiationAwareBeanPostProcessor的postProcessBeforeInstantiation方法
在这里插入图片描述
六.执行Bean的构造器
七.执行InstantiationAwareBeanPostProcessor的postProcessPropertyValues
在这里插入图片描述
八.为Bean注入属性
九.调用BeanNameAware的setBeanName方法
在这里插入图片描述
十.调用BeanFactoryAware的setBeanFactory方法
在这里插入图片描述
十一.执行BeanPostProcessor的postProcessBeforeInitialization方法
在这里插入图片描述
十二.调用InitializingBean的afterPropertiesSet方法
在这里插入图片描述
十二.调用的init-method属性指定的初始化方法
十三.执行beanPostProcessor的postProcessAfterInitialization方法
在这里插入图片描述
十四.执行InstantiationAwareBeanPostProcessor的postProcessAfterInstantiation方法
在这里插入图片描述
十五.容器初始化成功,执行正常调用后,下面销毁容器
十六.调用DisposableBean的destroy方法
在这里插入图片描述

十七.调用的destroy-method属性指定的初始化方法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值