Spring源码

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();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值