spring原始碼(7)alias標籤的解析
阿新 • • 發佈:2019-02-02
<bean id="some" class="src.com.Some"/>
<alias name="some" alias="someJava,oneBean,twoBean"/>
protected void processAliasRegistration(Element ele) {
//--獲取“name”、“alias”屬性
/*
* <bean id="some" class="src.com.Some"/>
* <alias name="some" alias="someJava,oneBean,twoBean"/>
*/
//獲取name屬性
String name = ele.getAttribute(NAME_ATTRIBUTE);
//獲取alias屬性
String alias = ele.getAttribute(ALIAS_ATTRIBUTE);
boolean valid = true;
if (!StringUtils.hasText(name)) {
getReaderContext().error("Name must not be empty", ele);
valid = false ;
}
if (!StringUtils.hasText(alias)) {
getReaderContext().error("Alias must not be empty", ele);
valid = false;
}
if (valid) {
try {
//註冊別名
getReaderContext().getRegistry().registerAlias(name, alias);
}
catch (Exception ex) {
getReaderContext().error("Failed to register alias '" + alias +
"' for bean with name '" + name + "'", ele, ex);
}
//通知監聽者
getReaderContext().fireAliasRegistered(name, alias, extractSource(ele));
}
}