在上一篇博客​​ Spring源码学习--ClassPathXmlApplicationContext(一)​​我们简单介绍了ClassPathXmlApplicationContext,接下来我们介绍一下FileSystemXmlApplicationContext

ApplicationContext应用上下文体系如下:

spring源码学习--FileSystemXmlApplicationContext(二)_FileSystemXmlApplica

FileSystemXmlApplicationContext的源码如下:

/**
* 并没有太多具体的操作,很多初始化操作都在其父类中
*/
public class FileSystemXmlApplicationContext extends AbstractXmlApplicationContext {

public FileSystemXmlApplicationContext() {
}

public FileSystemXmlApplicationContext(ApplicationContext parent) {
super(parent);
}
public FileSystemXmlApplicationContext(String configLocation) throws BeansException {
this(new String[] {configLocation}, true, null);
}
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException {
this(configLocations, true, null);
}
public FileSystemXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {
this(configLocations, true, parent);
}
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException {
this(configLocations, refresh, null);
}
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent)
throws BeansException {

//调用父类的构造函数
super(parent);
//设置配置文件的地址,如application.xml
setConfigLocations(configLocations);
if (refresh) {
//刷新容器,其实就是重新初始化容器
refresh();
}
}
@Override
protected Resource getResourceByPath(String path) {
if (path != null && path.startsWith("/")) {
path = path.substring(1);
}
return new FileSystemResource(path);
}
}