context:component-scan标签的诠释

本文解析了Spring框架中context:component-scan的作用及其如何自动扫描指定包内的组件,并自动注册为bean。此外还介绍了该配置如何包含context:annotation-config的功能,以及其自动注册的四个BeanPostProcessor的作用。

  

  XML中配置context:component-scan时,spring会自动的扫描这个包下被这些注解标识的类@Component,@Service,@Controller,@Repository,同时自动注册为bean

  同时context:component-scan包含了context:annotation-config的属性开关功能

  具体的属性注册四个BeanPostProcessor:

  AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、

  PersistenceAnnotationBeanPostProcessor 、RequiredAnnotationBeanPostProcessor。

  AutowiredAnnotationBeanPostProcessor的注册对应使用@Autowired注解,

  CommonAnnotationBeanPostProcessor注册对应使用@ Resource 、@ PostConstruct、@ PreDestroy注解,

  PersistenceAnnotationBeanPostProcessor 注册对应使用@PersistenceContext注解,

  RequiredAnnotationBeanPostProcessor注册对应使用@Required注解。

  由于我们一般使用context:component-scan(包含自动注入上方的四个BeanPostProcessor)功能的注解包的扫描,context:annotation-config的存在基本可以忽略了

  context:component-scan的子标签包含了

        <context:exclude-filter type="" expression=""/>
        <context:include-filter type="" expression=""/>

  context:exclude-filter:告知哪些类或者接口不需要被扫描

  context:include-filter:告知哪些类或者接口需要被扫描,并注册成bean类

  想到再补充吧

 



转载于:https://www.cnblogs.com/oldzhang1222/p/7988814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值