spring 记录

spring主要用于对bean对象的管理

加载Bean信息流程图

bean创建流程图

Bean的生命周期

 1 执行构造方法

 2 执行实现一堆的Aware接口

 3 执行BeanPostProcesor的before接口

 4 执行定义的init-method方法

 5 执行BeanPostProcessor的after方法

 6 调用DisposableBean方法

 7 调用distory方法

创建Bean
  doGetBean=>getSingleton()->singletonFactory.getObject()=>createBean()->doCreateBean()=>bean实例=》BeanWrapper实例=》addSingletonFactory(beanName,Bean实例)=》populateBean()

BeanWrapper

  对bean的属性的设置都是通过BeanWrapper来操作,这样的好处是方便扩展,很多的验证 判断都在这个类里做的了

Aop
  由AspectJAwareAdvisorAutoProxyCreator的BeanPostProcessor创建代理,在代理中根据方法获取拦截器(MethodInterceptor) ,遍历执行拦截器 (是一个递归的过程)

事物
  首先事物是基于AOP的 只是在执行方法的时候wl会获取一个关于事物的拦截器(TransactionInterceptor)

父子容器

  主要通过ContextLoaderListener监听器来实现,在该监听器中中会创建一个XmlWebApplicationContext类型的父IOC容器,并该对象存放在servletContext的"org.springframework.web.context.WebApplicationContext.ROOT"属性中

在DispatchServlet中会创建XmlWebApplicationContext IOC容器,然后根据"org.springframework.web.context.WebApplicationContext.ROOT"获取servletContext中父IOC容器 并将改值设置为子容器的父容器。

SpringMVC实现父子容器步骤:
  1 配置ContextLoaderListener监听器
  2 监听器创建XmlWebApplicationContext父IOC容器,并且其存放在servletContext中
  3 DispatchServlet创建XmlWebApplicationContext子容器
  4 从servletContext中获取父IOC容器,设置为子容器的父容器

原文地址:https://www.cnblogs.com/Tony100/p/13163162.html