1.入口
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
}
2.ClassPathXmlApplicationContext类图分析一下:
3.详细解析
/**
* 读取一个配置文件的构造方法
*/
public ClassPathXmlApplicationContext(String configLocation) throws BeansException {
this(new String[] {configLocation}, true, null);
}
/**
* 构造方法
* @param configLocations 配置文件列表
* @param refresh 是否刷新
* @param parent 父容器
*/
public ClassPathXmlApplicationContext(
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
throws BeansException {
super(parent); //调用父类构造方法,传入parent 这里为null
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
3.1 super方法详解
向上追溯
public AbstractXmlApplicationContext(@Nullable ApplicationContext parent) {
super(parent);
}
//===================================================================================
public AbstractRefreshableConfigApplicationContext(@Nullable ApplicationContext parent) {
super(parent);
}
//============================================