spring源码学习2 未完待续 欢迎评论与指教 开始有点乱 后期整理

来源:互联网 发布:linux修改root密码命令 编辑:程序博客网 时间:2024/05/21 18:38

为什么会默认读取/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};
  }
 }

 

原创粉丝点击