对于之前漫长的,最核心的Bean标签的解析就没什么好讲的了,
首先看看使用方法:
<bean id="car" name="cat0" class="entity.CarFactoryBean">
<property name="carInfo" value="超级跑车,400,2000000" />
</bean>
<alias name="car" alias="cat1,cat2" />
<alias name="car" alias="cat3,cat4" />
解析过程如下:
/**
* Process the given alias element, registering the alias with the registry.
*/
protected void processAliasRegistration(Element ele) {
// 获取beanName
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 {
// 注册alias
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));
}
}