入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

include-filter和exclude-filter

创建时间:2016-03-07 投稿人: 浏览次数:6570

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中的扫描设备进行事务处理。

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像