• 4.3 spring-嵌入式beans标签的解析


      对于嵌入式的beans标签,想信大家很少使用过,或者接触过,起码,我本人就没用过. 它非常类似于Import标签所提供的功能;

    使用如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
        <beans></beans>
    </beans> 

      对这个beans没什么太多可讲,解析代码如下:

     1 protected void doRegisterBeanDefinitions(Element root) {
     2         String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE);
     3         // 处理profile属性
     4         /*
     5          * this is header...
     6          * 
     7          * <beans profile = 'dev"></beans>
     8          * 
     9          * <beans profile = 'production"></beans>
    10          * 
    11          * web.xml
    12          * 
    13          * <context-param>
    14          * 
    15          * <param-name>Spring.profiles.active</param-name>
    16          * 
    17          * <param-value>dev</param-value>
    18          * 
    19          * </context-param>
    20          */
    21         if (StringUtils.hasText(profileSpec)) {
    22             Assert.state(this.environment != null,
    23                     "Environment must be set for evaluating profiles");
    24             String[] specifiedProfiles = StringUtils.tokenizeToStringArray(profileSpec,
    25                     BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
    26             if (!this.environment.acceptsProfiles(specifiedProfiles)) {
    27                 return;
    28             }
    29         }
    30 
    31         // Any nested <beans> elements will cause recursion in this method. In
    32         // order to propagate and preserve <beans> default-* attributes correctly,
    33         // keep track of the current (parent) delegate, which may be null. Create
    34         // the new (child) delegate with a reference to the parent for fallback purposes,
    35         // then ultimately reset this.delegate back to its original (parent) reference.
    36         // this behavior emulates a stack of delegates without actually necessitating one.
    37         // 专门处理解析
    38         BeanDefinitionParserDelegate parent = this.delegate;
    39         this.delegate = createDelegate(this.readerContext, root, parent);
    40         // 解析前留给子类实现
    41         preProcessXml(root);
    42 
    43         parseBeanDefinitions(root, this.delegate);
    44         // 解析后留给子类实现
    45         postProcessXml(root);
    46 
    47         this.delegate = parent;
    48     }
  • 相关阅读:
    Atmel Studio 烧录 Atmega328P(Arduiono)
    JSP内置对象详解及示例
    Hash Map 详细解释及示例
    19年双非学长逆袭985考研经验贴
    camelCase命名规范
    开始我的编程之旅!
    【转】堆和栈的区别
    现场编写类似strstr/strcpy函数
    【转】C++多态篇1一静态联编,动态联编、虚函数与虚函数表vtable
    【转】TCP协议中的三次握手和四次挥手(图解)
  • 原文地址:https://www.cnblogs.com/mjorcen/p/3649600.html
Copyright © 2020-2023  润新知