annotation-config和component-scan
以前学到<context:annotation-config></context:annotation-config>和<context:component-scan base-package="" ></context:component-scan>和两个配置的时候,只知道,annotation-config是用来开启xml配置中的bean对注解的支持,而component-scan是用来开启注解扫描,扫描指定包下面带注解的类。
今天看源码有了点新的收获:
annotation-config这个标签,实际上是注册各种BeanPostProcesser到BeanFactory,比如:AutowiredAnnotationBeanPostProcessor、RequiredAnnotationBeanPostProcessor这些,看名字就知道是干啥的了,因此xml配置的bean也就能通过注解注入了。
context:component-scan标签,实际是将配置的类路径转换为文件路径,比如:base-package="com.zby",转换为classpath*:com/zby/**/*.class,然后把这些加载的字节码封装成Resource,通过ASM读取字节码信息,封装成ScannedGenericBeanDefinition。这样就可以注册到BeanFactory了。同时,component-scan标签包含了annotation-config的功能,也注册了一系列对注解支持的BeanPostProcesser,所以,就不要同时出现这两个标签了。
看到这儿,也终于解决一个困惑,之前一直不知道asm在spring用来干嘛的,asm是用来扫描包,解析字节码的,cglib用来做代理增强。
annotation-config和component-scan的更多相关文章
- [Spring Boot] Use Component Scan to scan for Bean
Component Scan is important concept when we want to create Bean. Currently we know what, for the cla ...
- Spring ---annotation (重点)--Resource, Component 重要!!!
beans.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...
- 解决java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.robolectric.annotation.Config.application()
Deleting the .gradle folder worked for me too. Odd. Guessing some high level caching going on somewh ...
- 注解Annotation的IoC:从@Autowired到@Component
注解Annotation的IoC:从@Autowired到@Component 2017-01-23 目录 1 什么是注解2 不使用注解示例 2.1 com.springioc.animal.Mon ...
- Spring对注解(Annotation)处理【转】
1.从Spring2.0以后的版本中,spring也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5中引入的一个新特性,用于简化Bean的配置,某些场合可以 ...
- Advising controllers with the @ControllerAdvice annotation
The @ControllerAdvice annotation is a component annotation allowing implementation classes to be aut ...
- Spring 学习——Spring常用注解——@Component、@Scope、@Repository、@Service、@Controller、@Required、@Autowired、@Qualifier、@Configuration、@ImportResource、@Value
Bean管理注解实现 Classpath扫描与组件管理 类的自动检测与注册Bean 类的注解@Component.@Service等作用是将这个实例自动装配到Bean容器中管理 而类似于@Autowi ...
- 关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?
开心一刻 今天放学回家,气愤愤地找到我妈 我:妈,我们班同学都说我五官长得特别平 妈:你小时候爱趴着睡觉 我:你怎么不把我翻过来呢 妈:那你不是凌晨2点时候出生的吗 我:嗯,凌晨2点出生就爱趴着睡觉呗 ...
- Oracle 11gR2 RAC修改SCAN IP
一.查看当前环境: # grid用户 检查scan-ip地址的配置 [grid@node1 ~]$ srvctl config scan SCAN name: scan-cluster.com, Ne ...
- SpringBoot @Annotation
Annotation简介 Annotation是JDK1.5引入的特性,包含在java.lang.annotation包中. 它是附加在代码中的一些元信息,将一个类的外部信息与内部成员联系起来,在 编 ...
随机推荐
- Ubuntu14.04-LTS 从系统安装到配置可用
1.安装Ubuntu14.04LTS-64bit 使用U盘安装很方便快捷,可以使用老毛桃使用iso模式制作一个U盘启动盘,然后分区安装. 如果使用硬盘安装的话需要注意的问题是: 如果电脑上以前有Lin ...
- Cocos2d-x-2.2.2开发环境配置
1.安装各种软件: Android SDK Android NDK Apache Ant Python Eclipse(adt) Cygwin(可选) Java Cocos2d-x 2.系统环境变量配 ...
- 设计模式20:Memento 备忘录模式(行为型模式)
Memento 备忘录模式(行为型模式) 对象状态的回溯 对象状态的变化无端,如何回溯.恢复对象在某个点的状态? 动机(Motivation) 在软件构建过程中,某些对象的状态在转换过程中,可能由于某 ...
- 编写高质量代码改善C#程序的157个建议——建议143:方法抽象级别应在同一层次
建议143:方法抽象级别应在同一层次 看下面代码: class SampleClass { public void Init() { //本地初始化代码1 //本地初始化代码2 RemoteInit( ...
- strncmp用法说明
函数原型 int strcmp(char *str1,char * str2,int n) 功能 比较字符串str1和str2的前n个字符. 头文件 #include <string.h> ...
- cortex m0启动代码详解
转自:http://www.cnblogs.com/mddblog/p/4920063.html 阅读目录 概述 1.堆栈空间定义 2.存放中断向量表 3. 复位中断函数(Reset_Handler) ...
- alpha七天冲刺计划-第一天
alpha七天冲刺计划-第一天 一.团队会议: 内容:具体分配任务到个人,预估项目时间,确定UI样式. 合照: 二.团队成员任务认领: 李尤:界面UI设计. 彭迪彬:HTML+CSS部分实现. 任路乾 ...
- Maven整理笔记のMaven使用实践
我们通过实践来补充Maven构建的生命周期. 第一步:配置POM 接着上一篇Maven使用,我们先创建一个名为helloworld的文件夹,在helloworld目录下创建pom.xml文件,pom. ...
- Verilog HDL VGA Driver for Xilinx Nexys 4 适用于Nexys4的VGA驱动
/* * Function: VGA Timing Generator * Author: Liutianchen * Date: 2016-12-5 * Version: 6.0 * Environ ...
- Django Manage File
default_storage >>> from django.core.files.base import ContentFile >>> from django ...