spring源码解析 关于注解

本文深入探讨了Spring框架中注解的处理过程,从AbstractRefreshableApplicationContext的工厂刷新开始,详细讲解了如何通过AbstractXmlApplicationContext和XmlBeanDefinitionReader从XML加载bean定义。接着,介绍了BeanDefinitionParserDelegate作为bean定义的解析器,以及从META-INF下的spring.handler获取解析器的步骤。文章还特别关注了ContextNamespaceHandler,并展示了如何使用ClassPathScanningCandidateComponentProvider进行注解扫描,通过doScan方法获取带有注解的bean。最终,这些bean会被存储在beanDefinitionMap和beanDefinitionNames中。
摘要由CSDN通过智能技术生成

类 AbstractRefreshableApplicationContext
//工厂刷新 obtainFreshBeanFactory>refreshBeanFactory>loadBeanDefinitions

类 AbstractXmlApplicationContext
XmlBeanDefinitionReader从xml读取beandefinition loadBeanDefinitions 加载bean定义

//加载bean定义
public int loadBeanDefinitions(String... locations) throws BeanDefinitionStoreException {
Assert.notNull(locations, "Location array must not be null");
int counter = 0;
for (String location : locations) {
counter += loadBeanDefinitions(location);
}
return counter;
}

BeanDefinitionParserDelegate#bean定义的解析器

//格式化非默认的元素
public BeanDefinition parseCustomElement(Element ele, BeanDefinition containingBd) {
String namespaceUri = getNamespaceURI(ele);
//spring.handler读取该element的解析器
NamespaceHandler handler = 
this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri);
if (handler == null) {
error("Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]", ele);
return null;
}
return handler.parse(ele, new ParserContext(this.readerContext, this, containingBd));
}

META-INFO下的spring.handler


NamespaceHandlerResolver using mappings {http://www.w3.org/ns/ws-policy=org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler, http://www.springframework
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值