include-filter和exclude-filter

Spring学习中,遇到问题记录下,与大家分享,如有不对的地方还请多多指教。

<context:include-filter>和<context:exclude-filter>各代表引入和排除的的过滤。

在父容器中(applicationContext.xml)

<context:component-scan base-package="com.coamctech.eastlending">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
        <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan>

在子容器spring-mvc.xml中

<!-- 自动扫描且只扫描@Controller -->
    <context:component-scan base-package="com.coamctech.eastlending" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan>  

这样配置的原因是因为Spring会用到springmvc.xml 所以就会有父子容器的概念了.applicationcontext.xml是父容器,而springmvc.xml是子容器.在父容器中排除不扫描,在子容器中扫描,这样就避免了冲突。
Controller会进步前辈行扫描装配,而此时的Service还没有进行事务的加强处理,获得的将是原样的Service(没有经过事务加强处理) ,最后才是applicationContext.xml中的扫描设备进行事务处理。

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值