对于之前漫长的,最核心的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" />
解析过程如下:
1 /**
2 * Process the given alias element, registering the alias with the registry.
3 */
4 protected void processAliasRegistration(Element ele) {
5 // 获取beanName
6 String name = ele.getAttribute(NAME_ATTRIBUTE);
7 // 获取alias
8 String alias = ele.getAttribute(ALIAS_ATTRIBUTE);
9 boolean valid = true;
10 if (!StringUtils.hasText(name)) {
11 getReaderContext().error("Name must not be empty", ele);
12 valid = false;
13 }
14 if (!StringUtils.hasText(alias)) {
15 getReaderContext().error("Alias must not be empty", ele);
16 valid = false;
17 }
18 if (valid) {
19 try {
20 // 注册alias
21 getReaderContext().getRegistry().registerAlias(name, alias);
22 }
23 catch (Exception ex) {
24 getReaderContext().error(
25 "Failed to register alias '" + alias + "' for bean with name '"
26 + name + "'", ele, ex);
27 }
28 // 通知别名监听器
29 getReaderContext().fireAliasRegistered(name, alias, extractSource(ele));
30 }
31 }