以前学到<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的更多相关文章

  1. [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 ...

  2. Spring ---annotation (重点)--Resource, Component 重要!!!

    beans.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="ht ...

  3. 解决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 ...

  4. 注解Annotation的IoC:从@Autowired到@Component

    注解Annotation的IoC:从@Autowired到@Component 2017-01-23 目录 1 什么是注解2 不使用注解示例  2.1 com.springioc.animal.Mon ...

  5. Spring对注解(Annotation)处理【转】

    1.从Spring2.0以后的版本中,spring也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5中引入的一个新特性,用于简化Bean的配置,某些场合可以 ...

  6. Advising controllers with the @ControllerAdvice annotation

    The @ControllerAdvice annotation is a component annotation allowing implementation classes to be aut ...

  7. Spring 学习——Spring常用注解——@Component、@Scope、@Repository、@Service、@Controller、@Required、@Autowired、@Qualifier、@Configuration、@ImportResource、@Value

    Bean管理注解实现 Classpath扫描与组件管理 类的自动检测与注册Bean 类的注解@Component.@Service等作用是将这个实例自动装配到Bean容器中管理 而类似于@Autowi ...

  8. 关于 Spring Boot 中创建对象的疑虑 → @Bean 与 @Component 同时作用同一个类,会怎么样?

    开心一刻 今天放学回家,气愤愤地找到我妈 我:妈,我们班同学都说我五官长得特别平 妈:你小时候爱趴着睡觉 我:你怎么不把我翻过来呢 妈:那你不是凌晨2点时候出生的吗 我:嗯,凌晨2点出生就爱趴着睡觉呗 ...

  9. Oracle 11gR2 RAC修改SCAN IP

    一.查看当前环境: # grid用户 检查scan-ip地址的配置 [grid@node1 ~]$ srvctl config scan SCAN name: scan-cluster.com, Ne ...

  10. SpringBoot @Annotation

    Annotation简介 Annotation是JDK1.5引入的特性,包含在java.lang.annotation包中. 它是附加在代码中的一些元信息,将一个类的外部信息与内部成员联系起来,在 编 ...

随机推荐

  1. Excel分类汇总与数据有效性

    分类汇总就是把一些数据按照一个标准进行分类,然后按照相应的汇总方式进行汇总. 使用分类汇总之前先排序,否则汇总会出现很多类. 看如上这个表,如果按照所属区域分类,然后按照金额的总和汇总,在汇总之前就要 ...

  2. Thinkphp 导出大量数据 csv格式

    public function test2() { $user_count = M('department')->count(); $page = ceil($user_count / 1000 ...

  3. PHP 5.2 5.3 5.4 5.5 memcache dll扩展

    在windows下PHP5.2版本的memcache扩展dll文件好找,5.3的可能不是很好找,这里提供PHP5.2.5.3.5.4.5.5的php_memcache.dll扩展,需要的可以下载. 全 ...

  4. ssh的配置[待写]

    开机自启:/etc/rc.local /etc/init.d/ssh start 将 /etc/ssh/sshd_confg中PermitRootLogin no 改为yes,重新启动ssh服务.

  5. mysql 查询条件

    1简单查询   select* from 表名 select name as“姓名”fromstu     (把name改为名字) 2条件查询 where 后面跟条件  条件要写清楚 3模糊查询  l ...

  6. C# 加密(Encrypt) 解密(Decrypt) 操作类 java与 C# 可以相互加密解密

    public sealed class EncryptUtils { #region Base64加密解密 /// <summary> /// Base64加密 /// </summ ...

  7. 【微服务架构】SpringCloud之Eureka(服务注册和服务发现基础篇)(二)

    上篇文章讲解了SpringCloud组件和概念介绍,接下来讲解一下SpringCloud组件相关组件使用.原理和每个组件的作用的,它主要提供的模块包括:服务发现(Eureka),断路器(Hystrix ...

  8. CodeForces 499D. Name That Tune(概率dp)

    It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the followi ...

  9. Tomcat之Web站点部署

    上线代码有两种方式,第一种方式是直接将程序目录放在webapps目录下面,这种方式大家已经明白了,就不多说了.第二种方式是使用开发工具将程序打包成war包,然后上传到webapps目录下面.下面让我们 ...

  10. C++ 内敛函数

    在主调函数调用函数时,先将现场压入栈以保存现场-转去执行被掉函数-返回主调函数.现场出栈以恢复现场-继续往下执行. 为了减少函数调用的成本,特别是对于小型函数,C++提供了内敛函数(inline).C ...