1、BeanDefinitionParserDelegate:是一个委托类,用来辅助解析bean,类中声明了各种常量字符串,都是在Spring的配置文件中常见的属性值以及解析bean中的别名、类名、属性名等
2、BeanDefinitionRegistry:
以Map<String, BeanDefinition>的形式注册bean根据beanName 删除和获取 beanDefiniation
得到持有的beanDefiniation的数目
根据beanName 判断是否包含beanDefiniation
3、BeanDefinitionHolder:存储BeanDefinition以及相关信息
private final BeanDefinition beanDefinition;
private final String beanName;
private final String[] aliases;
4、可用于自定义
ReaderEventListener监听读取配置中Beans前、Bean的配置后的事件
DefaultBeanDefinitionDocumentReader可定义在读取xml之前、之后做的事
5、循环引用
5、ApplicationContext:一个应用的配置信息,包含应用的bean工厂、加载配置文件的方法、注册监听器的方法、解决国际化的方法;在spring中用处很大呀,在spring-mvc里出作为参数传进去进行bean的获取操作等
6、在创建bean之前进行bean定义的合并
final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
// …
createBean(beanName, mbd, args);
解决如下问题
<bean id="***parent***" abstract="true" class="br.com.ifpb.pw2.Anno.aop.ComplexObject"> <property name="properties"> <props> <prop key="administrator">administrator@example.com</prop> <prop key="support">support@example.com</prop> </props> </property> </bean> <bean id=***"child" parent="parent"***> <property name="properties"> <!-- the merge is specified on the child collection definition --> <props merge="true"> <prop key="sales">sales@example.com</prop> <prop key="support">support@example.co.uk</prop> </props> </property> </bean>
7、refresh()
//111111初始化一些配置
prepareRefresh();
//22222创建DefaultListableBeanFactory的bean的工厂包含读取配置文件,装配BeanDefinition:
DefaultSingletonBeanRegistry{
存储BeanDefinition
}
// Tell the subclass to refresh the internal bean factory.
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
// Prepare the bean factory for use in this context.
prepareBeanFactory(beanFactory);
// Allows post-processing of the bean factory in context subclasses.
postProcessBeanFactory(beanFactory);
// Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory);
// Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory);
// Initialize message source for this context.
initMessageSource();
// Initialize event multicaster for this context.
initApplicationEventMulticaster();
// Initialize other special beans in specific context subclasses.
onRefresh();
// Check for listener beans and register them.
registerListeners();
//真正创建bean的地方{
如果参数为依赖其他bean则会递归进行创建
}
// Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);
// Last step: publish corresponding event.
finishRefresh();