Spring随笔
- BeanFactory和ApplictionContext
- bean增强 AutowiredAnnotationBeanPostProcessor
- 工厂增强
BeanFactory和ApplictionContext
-
BeanFactory装载了bean实例,一个容器,提供了对bean的增删改查
-
ApplictionContext继承了factory,除此之外还装配了一系列的工厂后置处理器和bean后置处理器
- BeanFactoryPostProcessor工厂的增强,比如解析@Config,@ComponentScan等注解
- BeanPostProcessor bean的增强,比如解析@Autowired,@Resource等
bean增强 AutowiredAnnotationBeanPostProcessor
Field bean3 = Bean1.class.getDeclaredField("bean3");
//对字段依赖的封装
DependencyDescriptor dd1 = new DependencyDescriptor(bean3, false);
Object o = beanFactory.doResolveDependency(dd1, null, null, null);
System.out.println(o);
Method setBean2 = Bean1.class.getDeclaredMethod("setBean2", Bean2.class);
DependencyDescriptor dd2 =
//方法中可能会有多个参数
new DependencyDescriptor(new MethodParameter(setBean2, 0), true);
//交个bean工厂去解析依赖数据
Object o1 = beanFactory.doResolveDependency(dd2, null, null, null);
System.out.println(o1);