Mybatis分析(4)-属性解析propertiesEleme
作者:
不见当年三月花 | 来源:发表于
2019-08-29 10:07 被阅读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);
}
}
- 可以发现这里加载了properties的节点然后合并Variables,最终把属性赋值给了XMLConfigBuilder.parser和BaseBuilder.configuration,这样就可以在整个配置中使用了。
本文标题:Mybatis分析(4)-属性解析propertiesEleme
本文链接:https://www.haomeiwen.com/subject/cambectx.html
网友评论