Mybatis分析(4)-属性解析propertiesEleme

2019-08-29  本文已影响0人  不见当年三月花
org.apache.ibatis.builder.xml.XMLConfigBuilder#parseConfiguration
 private void propertiesElement(XNode context) throws Exception {
    if (context != null) {
      //加载properties节点
      Properties defaults = context.getChildrenAsProperties();
      String resource = context.getStringAttribute("resource");
      String url = context.getStringAttribute("url");
      //必须包含resource或者url
      if (resource != null && url != null) {
        throw new BuilderException("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
      }
      if (resource != null) {
        defaults.putAll(Resources.getResourceAsProperties(resource));
      } else if (url != null) {
        defaults.putAll(Resources.getUrlAsProperties(url));
      }
      //合并Variables
      Properties vars = configuration.getVariables();
      if (vars != null) {
        defaults.putAll(vars);
      }
      //赋值XMLConfigBuilder.parser
      parser.setVariables(defaults);
      //赋值BaseBuilder.configuration
      configuration.setVariables(defaults);
    }
  }
上一篇 下一篇

猜你喜欢

热点阅读