栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring源码-AbstractXmlApplicationContext-源码解读

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring源码-AbstractXmlApplicationContext-源码解读


public abstract class AbstractXmlApplicationContext extends AbstractRefreshableConfigApplicationContext {

	private boolean validating = true;


	
	public AbstractXmlApplicationContext() {
	}

	
	public AbstractXmlApplicationContext(@Nullable ApplicationContext parent) {
		super(parent);
	}


	
	public void setValidating(boolean validating) {
		this.validating = validating;
	}


	
	@Override
	protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
		// 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.
		beanDefinitionReader.setEnvironment(this.getEnvironment());
		beanDefinitionReader.setResourceLoader(this);
		beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

		// Allow a subclass to provide custom initialization of the reader,
		// then proceed with actually loading the bean definitions.
		initBeanDefinitionReader(beanDefinitionReader);
		loadBeanDefinitions(beanDefinitionReader);
	}

	
	protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
		reader.setValidating(this.validating);
	}

	
	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);
		}
	}

	
	@Nullable
	protected Resource[] getConfigResources() {
		return null;
	}

}
主要方法
方法名介绍
Loads the bean definitions via an XmlBeanDefinitionReader.经过一个 XmlBeanDefinitionReader 加载 bean definitions
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {}初始化这个 context 用于加载 bean definitions 的 bean definition reader
protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException {}使用给定的 XmlBeanDefinitionReader 加载 bean definitions
protected Resource[] getConfigResources() {}返回一个资源对象数组,引用构建这个 context 时的 XML bean definition 文件
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/768302.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号