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     }

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值