一起学SF框架系列4.3-spring-context-AbstractXmlApplicationContext

类作用

AbstractXmlApplicationContext继承于AbstractRefreshableConfigApplicationContext,其唯一作用实现祖先类的loadBeanDefinitions方法:从xml格式的配置中加载Bean定义。

类方法

loadBeanDefinitions(DefaultListableBeanFactory beanFactory)

为beanFactory加载bean定义。

@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
  		#为beanFactoy创建beanDefinition读取器
		// Create a new XmlBeanDefinitionReader for the given BeanFactory.
		XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

		// Configure the bean definition reader with this context's
		// resource loading environment.
		#设定 beanDefinition读取器 环境
		beanDefinitionReader.setEnvironment(this.getEnvironment());
		#设定 beanDefinition读取器 用到的资源加载器
		beanDefinitionReader.setResourceLoader(this);
		#设定 beanDefinition读取器 为默认的实体解析器
		beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

		// Allow a subclass to provide custom initialization of the reader,
		// then proceed with actually loading the bean definitions.
		#初始化 beanDefinition读取器 :设置xml合法性校验
		initBeanDefinitionReader(beanDefinitionReader);
		#把配置资源加载到 beanDefinition读取器
		loadBeanDefinitions(beanDefinitionReader);
	}

概括实现步骤:
1、为beanFactory创建XmlBeanDefinitionReader实例。
2、对XmlBeanDefinitionReaderr实例进行初始化设定。
3、从xml格式的Bean配置中加载Bean定义,xml格式的Bean配置来自configResources和configLocations(xml配置文件位置集合)。

loadBeanDefinitions(beanDefinitionReader)

	protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException {
		Resource[] configResources = getConfigResources();
		if (configResources != null) {
			reader.loadBeanDefinitions(configResources);
		}
		String[] configLocations = getConfigLocations();
		if (configLocations != null) {
			reader.loadBeanDefinitions(configLocations);
		}
	}

代码实现就是reader从configResources及configLocations加载类定义。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐享技术

每一个打赏,都是对我最大的鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值