ClassPathXmlApplicationContext
直接父类AbstractXmlApplicationContext
类作用:
- 初始化Resource[] resources,实现AbstractXmlApplicationContext 中的 getConfigResources()方法
或者 2. 调用父类AbstractRefreshableConfigApplicationContext 的setConfigLocations协助父类初始化 String[] configLocations.
注意: String[] configLocations最终会在AbstractXmlApplicationContext 中转换为Resource
成员变量
Resource[] resources; 主要用来在 AbstractXmlApplicationContext 中的方法 loadBeanDefinitions() 读取bean定义。
构造器
第一类构造器最终执行的:
public ClassPathXmlApplicationContext(
String [] configLocations, boolean refresh, @Nullable ApplicationContext parent) throws BeansException {
super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
第二类构造器最终执行的:
public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, @Nullable ApplicationContext parent) throws BeansException {
super(parent);
Assert.notNull(paths, "Path array must not be null");
Assert.notNull(clazz, "Class argument must not be null");
this.configResources = new Resource[paths.length];
for (int i = 0; i < paths.length; i++) {
this.configResources[i] = new ClassPathResource(paths[i], clazz);
}
refresh();
}