对于嵌入式的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没什么太多可讲,解析代码如下:

 protected void doRegisterBeanDefinitions(Element root) {
String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE);
// 处理profile属性
/*
* this is header...
*
* <beans profile = 'dev"></beans>
*
* <beans profile = 'production"></beans>
*
* web.xml
*
* <context-param>
*
* <param-name>Spring.profiles.active</param-name>
*
* <param-value>dev</param-value>
*
* </context-param>
*/
if (StringUtils.hasText(profileSpec)) {
Assert.state(this.environment != null,
"Environment must be set for evaluating profiles");
String[] specifiedProfiles = StringUtils.tokenizeToStringArray(profileSpec,
BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
if (!this.environment.acceptsProfiles(specifiedProfiles)) {
return;
}
} // Any nested <beans> elements will cause recursion in this method. In
// order to propagate and preserve <beans> default-* attributes correctly,
// keep track of the current (parent) delegate, which may be null. Create
// the new (child) delegate with a reference to the parent for fallback purposes,
// then ultimately reset this.delegate back to its original (parent) reference.
// this behavior emulates a stack of delegates without actually necessitating one.
// 专门处理解析
BeanDefinitionParserDelegate parent = this.delegate;
this.delegate = createDelegate(this.readerContext, root, parent);
// 解析前留给子类实现
preProcessXml(root); parseBeanDefinitions(root, this.delegate);
// 解析后留给子类实现
postProcessXml(root); this.delegate = parent;
}
04-27 18:10