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包中. 它是附加在代码中的一些元信息,将一个类的外部信息与内部成员联系起来,在 编 ...
随机推荐
- HBase预分区方法
(what)什么是预分区? HBase表在刚刚被创建时,只有1个分区(region),当一个region过大(达到hbase.hregion.max.filesize属性中定义的阈值,默认10GB)时 ...
- [GO]json解析到map
package main import ( "encoding/json" "fmt" ) var str string func main() { m := ...
- phpstury 升级mysql5.7
今天在往本地导数据表的时候老是报错: [Err] 1294 - Invalid ON UPDATE clause for '字段名' column 报错的数据表字段: `字段名` datetime D ...
- yii2 定义友好404
1.frontend->config->main.php添加如下: 'errorHandler' => [ 'errorAction' => 'site/error', ], ...
- Discuz核心函数的解析
dz采用的是多入口的方式,在每个入口函数你能看到引用,启动核心类的语句(其余省略),如下: require './source/class/class_core.php'; C::app()-> ...
- python之CSV文件格式
1.csv文件是以一些以逗号分隔的值 import csv filename = "wenjian.csv" with open(filename) as f: reader = ...
- 【小梅哥SOPC学习笔记】设置Eclipse在编译(build)前自动保存源代码文件
设置Eclipse在编译(build)前自动保存源代码文件 Eclipse 常用设置之让Eclipse在编译(build)前自动保存源代码文件 一.让Eclipse在编译(build)前自动保存源代码 ...
- 20、Semantic-UI之数据验证
20.1 实现数据验证 在很多前端框架中都提供了数据验证的操作,比如jQuery的验证框架等,但是jQuery的验证框架js文件太多:在使用Semantic-UI框架的时候只需要导入semanti ...
- VC中CDC与HDC的区别以及二者之间的转换
CDC是MFC的DC的一个类 HDC是DC的句柄,API中的一个类似指针的数据类型. MFC类的前缀都是C开头的 H开头的大多数是句柄 这是为了助记,是编程读\写代码的好的习惯. CDC中所有MFC的 ...
- windows8.1 windows defender service无法启动解决方案
分析:当pc安装第三方杀毒软件,比如360杀毒,这时候360会强制关闭mse杀毒服务,无法在服务栏目里启动.由于windows defender service是系统强制启动进程,无法在系统启动后进行 ...