include-filter和exclude-filter的区别

include-filter和exclude-filter在Spring的@Component-scan中用于控制Bean的扫描范围。默认情况下,会扫描@Component及其子注解@Service、@Repository。设置include-filter仅扫描@Controller,但若不设置use-default-filters为false,仍会扫描其他子注解。exclude-filter则先执行,用于黑名单过滤,然后include-filter执行白名单过滤。
摘要由CSDN通过智能技术生成


include-filter和exclude-filter的区别:

前者是扫描,后者是排除扫描。
下面是父子容器配置时需要注意的。




如下方式可以成功扫描到@Controller注解的Bean,不会扫描@Service/@Repository的Bean。正确

 

Java代码   收藏代码
  1.  <context:component-scan base-package="org.bdp.system.test.controller">   
  2.      <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>   
  3. </context:component-scan>  

  

但是如下方式,不仅仅扫描@Controller,还扫描@Service/@Repository的Bean,可能造成一些问题

 

Java代码   收藏代码
  1.  <context:component-scan base-package="org.bdp">   
  2.      <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>   
  3. </context:component-scan>  
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值