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     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM