4.1 spring-alias 标签的解析;

  对于之前漫长的,最核心的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     }

 

转载于:https://my.oschina.net/u/1590001/blog/268198

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值