容器接口实现

 

BeanFactory的实现

 
notion image
发现spring容器最后只有Config 这个bean对象@Bean注解并没有生效

不会主动调用 BeanFactory 后处理器

notion image
容器中多了一些处理器对象
 
执行BeanFactory后置处理器
notion image
打印bean1对象的成员变量bean2

不会主动添加 Bean 后处理器

System.out.println(beanFactory.getBean(Bean1.class).getBean2());
notion image
添加bean后处理器
notion image

不会主动初始化单例

getBean2的时候bean2开始构造
beanFactory.preInstantiateSingletons(); // 准备好所有单例 取消延迟加载 在beanFactory.getBean(Bean1.class) 之前完成bean1和bean2的构造
notion image
 

ApplicationContext的实现

ClassPathXmlApplicationContext

 
resource目录下的xml文件
notion image

FileSystemXmlApplicationContext

加载文件需要指定文件系统中的路径

AnnotationConfigApplicationContext

基于注解配置类创建容器
notion image

AnnotationConfigServletWebServerApplicationContext

基于配置类创建,用于web环境
 
notion image