Springboot----Bean的生命周期

1.BeanDefinition接口 :定义bean的属性信息

      Root bean: class [org.springframework.context.annotation.ConfigurationClassPostProcessor];

      scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null

2.Bean创建对象(实例化)和属性赋值(set方法 构造方法  autowired ) 通过扩展点扩展Bean的能力。        Object a=  new Object()  a.set(int  id)   a(int id, String name){ 构造函数}  属性自动装配 。

3.Bean的生命周期 : 1.Bean的创建(BeanDefinition);2.Bean的属性初始化;3.Bean初始化完成(单例实例 原型等Scope) 4.Bean的注销 5.Bean的销毁。容器刷新 refresh   重复。

4.Bean对象初始化过程中的扩展点: 接口形式   接口有很多实现对象  实现对象有不同的方法实现。通过不同的对象操作不同的IOC容器对象。

 1.BeanFactoryPostProcessor接口开始实例化:  获取beanFactory 给bean对象添加属性。

    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)    直接修改beandefinition 的属性信息。或者增加属性。

    2.BeanPostProcessor接口开始实例化: 

    3.InstantiationAwareBeanPostProcessor       

public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName)
        <---①Bean创建
public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) 
       <----属性设置
    
      public Object postProcessBeforeInitialization(Object bean, String beanName)   上面第三步 之前 执行
    Aware接口方法:
BeanNameAware EnvironmentAware BeanFactoryAware ResourceLoaderAware ApplicationContextAware
       <------bean初始化完成
    public Object postProcessAfterInitialization(Object bean, String beanName)    上面 第三步 之后  执行

    

      

原文地址:https://www.cnblogs.com/chencn/p/12513030.html