org.apache.ibatis.builder.xml.XMLConfigBuilder#parseConfiguration
private void propertiesElement(XNode context) throws Exception {
if (context != null) {
//加載properties節(jié)點(diǎn)
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);
}
}
- 可以發(fā)現(xiàn)這里加載了properties的節(jié)點(diǎn)然后合并Variables,最終把屬性賦值給了XMLConfigBuilder.parser和BaseBuilder.configuration,這樣就可以在整個(gè)配置中使用了唠雕。