为什么会默认读取/WEB-INF/applicationContext.xml文件呢。
前面提到ClassLoader中会默认读取ContextLoader.properties文件,从而取出org.springframework.web.context.support.XmlWebApplicationContext,默认初始化XmlWebApplicationContext
那么看看XmLWebApplicationContext中的内容
/** Default config location for the root context */
public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml";
//获取默认的配置位置 当namespace不为空的时候,默认的配置文件就是自己控制的,否则的话则默认使用/WEB-INF/applicationContext.XML配置文件
@Override
protected String[] getDefaultConfigLocations() {
if (getNamespace() != null) {
return new String[] {DEFAULT_CONFIG_LOCATION_PREFIX + getNamespace() + DEFAULT_CONFIG_LOCATION_SUFFIX};
}
else {
return new String[] {DEFAULT_CONFIG_LOCATION};
}
}