|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
Spring框架源码版本5.3.x
|
|
|
|
|
|
|
|
|
|
### 框架源码的前置知识
|
|
|
|
|
|
|
|
|
|
* 设计模式
|
|
|
|
@ -24,12 +26,14 @@ xxbean.method();
|
|
|
|
|
|
|
|
|
|
#### SSM框架项目中spring处理bean的主要流程
|
|
|
|
|
|
|
|
|
|
* 加载xml文件
|
|
|
|
|
* 解析xml文件
|
|
|
|
|
* 加载bean定义文件,一般是xml文件或者注解
|
|
|
|
|
* 解析bean定义文件
|
|
|
|
|
* 封装BeanDefinition
|
|
|
|
|
* 实例化
|
|
|
|
|
* 放到容器中
|
|
|
|
|
* 从容器中获取
|
|
|
|
|
* 处理PostProcessor
|
|
|
|
|
* 准备监听器
|
|
|
|
|
* 创建代理(JDK或者Cglib),使用反射实例化
|
|
|
|
|
* 属性填充和初始化
|
|
|
|
|
* 销毁
|
|
|
|
|
|
|
|
|
|
容器使用map保存bean,map的key和value内容
|
|
|
|
|
|序号| Key | Value |
|
|
|
|
@ -39,7 +43,7 @@ xxbean.method();
|
|
|
|
|
|3| String | ObjectFactory |
|
|
|
|
|
|4| String | BeanDefinition |
|
|
|
|
|
|
|
|
|
|
## Spring创建Bean过程中用到的主要接口
|
|
|
|
|
## Spring创建Bean过程中用到的主要接口和类
|
|
|
|
|
|
|
|
|
|
* BeanDefinitionReader
|
|
|
|
|
* BeanDefinition
|
|
|
|
@ -52,6 +56,7 @@ xxbean.method();
|
|
|
|
|
* Aware
|
|
|
|
|
* BeanNameAware
|
|
|
|
|
* AbstractAutoProxyCreator
|
|
|
|
|
* ConfigurationClassPostProcessor
|
|
|
|
|
|
|
|
|
|
#### BeanDefinitionReader
|
|
|
|
|
|
|
|
|
@ -160,3 +165,6 @@ ApplicationContext可以在其 bean 定义中自动检测 BeanPostProcessor bean
|
|
|
|
|
子类可以应用任何策略来决定是否要代理一个 bean,例如 按类型、按名称、按定义详细信息等。它们还可以返回应仅应用于特定 bean 实例的其他拦截器。 一个简单的具体实现是 {@link BeanNameAutoProxyCreator},通过给定名称识别要代理的 bean。
|
|
|
|
|
|
|
|
|
|
可以使用任意数量的 {@link TargetSourceCreator} 实现来创建自定义目标源:例如,池化原型对象。 即使没有建议,自动代理也会发生,只要 TargetSourceCreator 指定自定义 {@link org.springframework.aop.TargetSource}。 如果没有设置 TargetSourceCreators,或者没有匹配项,默认情况下将使用 {@link org.springframework.aop.target.SingletonTargetSource} 来包装目标 bean 实例。
|
|
|
|
|
|
|
|
|
|
#### ConfigurationClassPostProcessor
|
|
|
|
|
启动过程中处理@Configuration注解。通过<context:annotation-config/>或者<context:component-scan/>标签注册,也可以通过其他BeanFactoryPostProcessor手动注册。他实现了PriorityOrdered接口,@Configuration注解修饰的类中所有具有bean定义的方法在所有BeanFactoryPostProcessor执行之前注册。
|
|
|
|
|