1.IOC容器的加载

1)Resource定位(容器寻找数据的过程)

2)载入(把用户定义好的bean表示成IOC容器内部的数据结构即:BeanDefinition)

3)注册(把载入的BeanDefinition注册到IOC容器) 

 Spring之IOC容器的加载过程

 

 

 Spring之IOC容器的加载过程

1.1Bean的创建 

bean是什么时候创建的?第一次getBean的时候

 

1)检查bean是否已经存在,根据beanName获取BeanDefinition,递归获取依赖bean,根据不同属性的bean调用方法创建bean(如Singleton的,Scope的,Property的)

Spring之IOC容器的加载过程doGetBean

2)检查循环引用,设置bean的属性

Spring之IOC容器的加载过程createBean

3)通过不同的方式创建bean,策略模式,默认SimpleInstantiationStrategy,提供两种实例化方式,一种是BeanUtils(使用JVM的反射功能),另外一种是Cglib(字节码生成类库)

Spring之IOC容器的加载过程createBeanInstance

4)属性注入如@Autowired等

Spring之IOC容器的加载过程属性注入populateBean

 

1.2 实例化Bean的策略

1.Cglib

Spring之IOC容器的加载过程

 

1.3Bean创建流程

Spring之IOC容器的加载过程

 

 

Spring之IOC容器的加载过程

 

 

 

 

 

 Spring之IOC容器的加载过程

  

Spring之IOC容器的加载过程
 <bean id="testSpringBean" class="com.bkjk.cf.receivablesfinancing.service.TestSpringBean" init-method="init"
          destroy-method="destory">
        <property name="propertyAge" value="343434"/>
        <property name="propertyName" value="zhanfdifjidfj"/>

    </bean>
bean.xml

相关文章: