本文承接前文Spring源码情操陶冶-自定义节点的解析,分析spring中的context:annotation-config节点如何被解析

源码概览

BeanDefinitionParser接口的实现方法parse代码如下

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element); // Obtain bean definitions for all relevant BeanPostProcessors.主要的作用就是配置BeanPostProcessors
Set<BeanDefinitionHolder> processorDefinitions =
AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source); // Register component for the surrounding <context:annotation-config> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition); // Nest the concrete beans in the surrounding component.
for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
} // Finally register the composite component.
parserContext.popAndRegisterContainingComponent(); return null;
}

由上可述,我们明白了为什么配置了context:component-scan节点等同于不需要配置context:annotation-config节点,此处的代码类同与ComponentScanBeanDefinitionParser#registerComponents方法,所以这里就不赘述了,可见>>>Spring源码情操陶冶-ComponentScanBeanDefinitionParser文件扫描解析器ComponentScanBeanDefinitionParser#registerComponents版块

小结

注册多个BeanPostProcessor接口实现类【供后续spring调用统一接口进行解析,比如>>>Spring源码情操陶冶-AbstractApplicationContext#invokeBeanFactoryPostProcessors可会执行解析@Configuration】具体的有

  • ConfigurationClassPostProcessor解析@Configuration注解类

  • AutowiredAnnotationBeanPostProcessor解析@Autowired/@Value注解

  • RequiredAnnotationBeanPostProcessor解析@Required注解

  • CommonAnnotationBeanPostProcessor解析@Resource注解

  • PersistenceAnnotationBeanPostProcessor解析JPA注解,持久层

Spring源码情操陶冶-AnnotationConfigBeanDefinitionParser注解配置解析器的更多相关文章

  1. Spring源码情操陶冶-PropertyPlaceholderBeanDefinitionParser注解配置解析器

    本文针对spring配置的context:property-placeholder作下简单的分析,承接前文Spring源码情操陶冶-自定义节点的解析 spring配置文件应用 <context: ...

  2. Spring源码情操陶冶-ComponentScanBeanDefinitionParser文件扫描解析器

    承接前文Spring源码情操陶冶-自定义节点的解析,本文讲述spring通过context:component-scan节点干了什么事 ComponentScanBeanDefinitionParse ...

  3. Spring源码情操陶冶-AOP之ConfigBeanDefinitionParser解析器

    aop-Aspect Oriented Programming,面向切面编程.根据百度百科的解释,其通过预编译方式和运行期动态代理实现程序功能的一种技术.主要目的是为了程序间的解耦,常用于日志记录.事 ...

  4. Spring源码情操陶冶-自定义节点的解析

    本文承接前文Spring源码情操陶冶-DefaultBeanDefinitionDocumentReader#parseBeanDefinitions,特开辟出一块新地来啃啃这块有意思的骨头 自定义节 ...

  5. SpringMVC源码情操陶冶-ResourcesBeanDefinitionParser静态资源解析器

    解析mvc:resources节点,控制对静态资源的映射访问 查看官方注释 /** * {@link org.springframework.beans.factory.xml.BeanDefinit ...

  6. Spring源码情操陶冶-AOP之Advice通知类解析与使用

    阅读本文请先稍微浏览下上篇文章Spring源码情操陶冶-AOP之ConfigBeanDefinitionParser解析器,本文则对aop模式的通知类作简单的分析 入口 根据前文讲解,我们知道通知类的 ...

  7. Spring源码情操陶冶-tx:advice解析器

    承接Spring源码情操陶冶-自定义节点的解析.本节关于事务进行简单的解析 spring配置文件样例 简单的事务配置,对save/delete开头的方法加事务,get/find开头的设置为不加事务只读 ...

  8. Spring源码情操陶冶#task:executor解析器

    承接Spring源码情操陶冶-自定义节点的解析.线程池是jdk的一个很重要的概念,在很多的场景都会应用到,多用于处理多任务的并发处理,此处借由spring整合jdk的cocurrent包的方式来进行深 ...

  9. Spring源码情操陶冶-AbstractApplicationContext#finishBeanFactoryInitialization

    承接前文Spring源码情操陶冶-AbstractApplicationContext#registerListeners 约定web.xml配置的contextClass为默认值XmlWebAppl ...

随机推荐

  1. Codeforces 754A Lesha and array splitting(简单贪心)

    A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ...

  2. UOJ#152. 【UR #10】汉诺塔

    题目:http://uoj.ac/problem/152 orzKPM... 分治,把数字是l~mid的拿出来放在一根柱子上,mid+1~r放在另一根柱子上.如此递归下去,每次递归只是改一下方向,l, ...

  3. android动画源码合集、动态主题框架、社交app源码等

    Android精选源码 仿MIUI果冻视图-BouncingJellyView   一个快速易用的动态主题框架   android动画效果集合源码   android使用Kotlin开发的Dribbb ...

  4. c++只能编译无法运行或许缺少命令

    -mwindows -lcomctl32 -lwinmm -lws2_32 -lodbc32 -lmysql   -lwinspool1.工具-编译选项-编译器-在连接器命令行加入以下命令:-mwin ...

  5. [数据库] SQL查询语句表行列转换及一行数据转换成两列

    原文来自:http://blog.csdn.net/Eastmount/article/details/50559008 本文主要讲述了SQL查询语句表之间的行列转换,同时也包括如何将一行数据转换成两 ...

  6. C#历年来最受欢迎功能

    不定时更新翻译系列,此系列更新毫无时间规律,文笔菜翻译菜求各位看官老爷们轻喷,如觉得我翻译有问题请挪步原博客地址 本博文翻译自: http://www.dotnetcurry.com/csharp/1 ...

  7. 番外篇--Moddule Zero启动模板

    1.3 ABPZero - 启动模板 1.3.1 简介 使用ABP和moudle-zero开始一个新项目的最简单的方式是在模板页创建模板.记住要勾选 Include module zero. 在创建并 ...

  8. Switch 语句

    如果您希望有选择地执行若干代码块之一,请使用 Switch 语句. 使用 Switch 语句可以避免冗长的 if..elseif..else 代码块. 语法 工作原理: 对表达式(通常是变量)进行一次 ...

  9. Centos系统下Lamp环境的快速搭建(超详细)

    lamp的搭建对于初学者是一件很头疼的事情,所以借此机会把自己当初快速搭建linux+apche+mysql+php的方法分享大家希望能到你. 工具/原料 虚拟机及Centos操作系统 Linux基本 ...

  10. Html5+js测试题(开发版)

    ------------------------------------------------ 1. 谈谈你对js闭包的理解: 使用闭包主要是为了设计私有的方法和变量.闭包的优点是可以避免全局变量的 ...