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 文件 |