好记性不如烂笔头。记一下对ApplicationContext实例化的过程的吧。
代码:
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
首先进入的代码是:
static {
ContextClosedEvent.class.getName();
}
这个代码块在AbstractApplicationContext里,是ClassPathXmlApplicationContext的父类,所以静态代码块先运行。(所以这句代码的作用是啥呢?求大佬指导)
进入代码:
public ClassPathXmlApplicationContext(String configLocation) throws BeansException {
this(new String[]{configLocation}, true, (ApplicationContext)null);
}
之后调用本类的另一个构造方法
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) throws BeansException {
super(parent);
this.setConfigLocations(configLoc