spring源码解析 关于注解

来源:互联网 发布:2011年小牛夺冠数据 编辑:程序博客网 时间:2024/06/06 12:10

类 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.org/schema/jdbc=org.springframework.jdbc.config.JdbcNamespaceHandler, http://www.springframework.org/schema/oxm=org.springframework.oxm.config.OxmNamespaceHandler, http://cxf.apache.org/jaxws=org.apache.cxf.jaxws.spring.NamespaceHandler, http://schemas.xmlsoap.org/ws/2004/09/policy=org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler, http://cxf.apache.org/core=org.apache.cxf.bus.spring.NamespaceHandler, http://www.springframework.org/schema/c=org.springframework.beans.factory.xml.SimpleConstructorNamespaceHandler, http://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler, http://www.springframework.org/schema/mvc=org.springframework.web.servlet.config.MvcNamespaceHandler, http://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler, http://www.w3.org/2006/07/ws-policy=org.apache.cxf.ws.policy.spring.PolicyNamespaceHandler, http://cxf.apache.org/simple=org.apache.cxf.frontend.spring.NamespaceHandler, http://cxf.apache.org/policy=org.apache.cxf.ws.policy.spring.NamespaceHandler, http://mybatis.org/schema/mybatis-spring=org.mybatis.spring.config.NamespaceHandler, http://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler, http://www.springframework.org/schema/tx=org.springframework.transaction.config.TxNamespaceHandler, http://cxf.apache.org/bindings/soap=org.apache.cxf.binding.soap.spring.NamespaceHandler, http://cxf.apache.org/transports/http/configuration=org.apache.cxf.transport.http.spring.NamespaceHandler, http://www.springframework.org/schema/cache=org.springframework.cache.config.CacheNamespaceHandler, http://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler, http://www.springframework.org/schema/task=org.springframework.scheduling.config.TaskNamespaceHandler, http://www.springframework.org/schema/web-services=org.springframework.ws.config.WebServicesNamespaceHandler, http://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler, http://cxf.apache.org/ws/addressing=org.apache.cxf.ws.addressing.spring.NamespaceHandler, http://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler}

//本例子以ContextNamespaceHandler为例子 获取解析器

public class ContextNamespaceHandler extends NamespaceHandlerSupport {public void init() {registerBeanDefinitionParser("property-placeholder", new PropertyPlaceholderBeanDefinitionParser());registerBeanDefinitionParser("property-override", new PropertyOverrideBeanDefinitionParser());registerBeanDefinitionParser("annotation-config", new AnnotationConfigBeanDefinitionParser());registerBeanDefinitionParser("component-scan", new ComponentScanBeanDefinitionParser());registerBeanDefinitionParser("load-time-weaver", new LoadTimeWeaverBeanDefinitionParser());registerBeanDefinitionParser("spring-configured", new SpringConfiguredBeanDefinitionParser());registerBeanDefinitionParser("mbean-export", new MBeanExportBeanDefinitionParser());registerBeanDefinitionParser("mbean-server", new MBeanServerBeanDefinitionParser());}}

//刷新定义的注解
ClassPathScanningCandidateComponentProvider
扫描注解Set doScan(String… basePackages) 获取所有注解的bean

spring的bean都放在beanDefinitionMap
spring的names放在beanDefinitionNames

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 华为手机自动安装软件怎么办 手机在实体店买贵了怎么办 日本买的kindle坏了怎么办 华为麦芒4屏幕失灵怎么办 华为麦芒6屏幕失灵怎么办 手机为什么总显示内存不足怎么办 小米云服务满了怎么办 魅蓝s6声音小怎么办 华为畅享7s丢失怎么办 华为耳机孔坏了怎么办 苹果手机耳机插孔坏了怎么办 荣耀8听筒声音小怎么办 荣耀8听筒音量小怎么办 华为荣耀6声音小怎么办 华为荣耀v8通话声音小怎么办 华为p20没有耳机孔怎么办 华为荣耀手机耳机声音小怎么办 小米5x显示耳机怎么办 手机进水听音乐人声小怎么办 华为荣耀v8手机音量小怎么办 手机充电孔松了怎么办 华为荣耀7卡顿怎么办 华为手机话筒没声音怎么办 苹果x耳机进水了怎么办 苹果6p进水了怎么办 华为手机声音变耳机模式怎么办 手机设置成耳机模式怎么办 opop耳机一个没有声音怎么办 oppo手机上显示耳机模式怎么办 微信显示耳机模式怎么办 微信变成耳机模式怎么办 5s变成耳机模式怎么办 华为手机一直是耳机模式怎么办 华为手机进水了耳机模式怎么办 蓝牙耳机通话声音小怎么办 华为手机自动进入耳机模式怎么办 华为手机耳机怎么挂了电话怎么办 华为手机听筒声音小怎么办 华为p9手机听筒声音小怎么办 苹果6总是耳机模式怎么办 苹果没有插耳机模式怎么办