无聊看看了spring的源码,并画了uml图。

spring执行流程:
1: 加载spring.xml文件
2: 创建xml文件解析器 
3: 获取命名空间,即在spring.xml文件中的 http://www.springframework.org/schema/context
4: 根据命名空间找到命名空间处理器,在命名空间处理器中包含 对应:
命名空间解析器:包含多个属性解析器:
{annotation-config=org.springfr[email protected]21cdca84, mbean-server=org[email protected]4daab172, spring-configured=org.spri[email protected]167db34, property-placeholder=org.springf[email protected]496833a4, load-time-weaver=org.sp[email protected]581679a2, component-scan=org.sprin[email protected]2b8ba7dc, property-override=org.spri[email protected]5db972d9, mbean-export=org[email protected]3a2334a1
}
         <context:component-scan />  每一个 这样的标签都会对应一个解析器
         <context:annotation-config/>
         <context:load-time-weaver/>
         <context:mbean-export/>
         <context:mbean-server/>
         <context:property-override/>
         <context:property-placeholder/>
         <context:spring-configured/>

5: 根据处理器 获得 标签<context:component-scan /> 解析器 ComponentScanBeanDefinitionParser

6:ComponentScanBeanDefinitionParser解析器开始解析调用Parse 方法

7:根据<context:component-scan /> 中的扫描路径进行处理,并加载class文件信息

8:利用ASM技术去解读class文件获得class中的信息,spring提供了一些ASM类例如:
import org.springframework.asm.AnnotationVisitor; //查看class文件有哪些注解
import org.springframework.asm.Attribute;         //查看class文件有哪些属性
import org.springframework.asm.ClassVisitor;      //
import org.springframework.asm.FieldVisitor;      //查看class文件有哪些字段
import org.springframework.asm.MethodVisitor;      //查看class文件有哪些方法
import org.springframework.asm.Opcodes;
import org.springframework.asm.SpringAsmInfo;

9:解析完class文件生成beandefinition 对象,beandefinition对象是对bean 定义描述,例如,创建bean的策略,初始方法,等等。

10:最后根据beandefinition 生成 bean对象,放入 spring容器中,spring容器是一个ConcurrentHashMap

以上是spring的大体流程,下面是我跟踪spring源码所画的springUML图:长卷图

无聊看看了spring的源码,并画了uml图。