基本流程如下:

spring全流程

 

上面是spring容器的一个基本使用,跟着代码追进去:

spring全流程

 

默认的构造方法,核心:refresh方法

 

spring全流程

 

 

 

基本流程:

(1)创建ListableBeanFactory

(2) 将xml中配置的bean加载到容器中(并不是完全体,只是BeanDinfiation)

(3)一些中间操作

(4)初始化所有的单例bean


 

上面是概述,下面是详细展开

(1)创建容器前的准备工作

设置容器的一些状态(使用atomBoolean来实现)

(2) 创建容器,同时加载bean

spring全流程

 

上面的代码就是主要的过程

根据上面的代码可以看出来:

(1)applicationContext与beanFactory是有很大区别的,applicationContext将有关bean的创建相关的事务托管给DefaultListableBeanFactory(为什么是这个类,关键看这个类的结构,这个类是configruationListableBeanFactory和AbstractAutowairedCapbleBeanFactory的子类,具有最强大的功能)

customizeBeanFactory(设置两个属性)

最关键的解析bean

 通过XmlBeanDefinitionReader将xml中的bean都解析到BeanDifinationMap中

开始初始化单例

 

spring全流程

相关文章:

  • 2021-12-14
  • 2021-05-28
  • 2021-04-09
  • 2021-07-22
  • 2021-11-27
  • 2021-07-16
猜你喜欢
  • 2021-07-30
  • 2021-10-22
  • 2021-06-01
  • 2021-04-01
  • 2022-01-20
  • 2022-12-23
  • 2021-09-28
相关资源
相似解决方案