首页 > 编程语言 > 详细

spring中的context:include-filter和context:exclude-filter的区别

时间:2017-08-01 10:45:11      阅读:207      评论:0      收藏:0      [点我收藏+]

http://blog.csdn.net/w2393040183/article/details/50749851

 

    <!-- 扫描@Controller注解 -->
    <context:component-scan base-package="com.fq.controller">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

可以看出要把最终的包写上,而不能这样写base-package=”com.fq”。这种写法对于include-filter来讲它都会扫描,而不是仅仅扫描@Controller。哈哈哈,这点需要注意。他一般会导致一个常见的错误,那就是事务不起作用,补救的方法是添加use-default-filters=”false”。

(2)在Spring-Context.xml中有如下配置:

    <!-- 配置扫描注解,不扫描@Controller注解 -->
    <context:component-scan base-package="com.fq">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

可以看到,他是要扫描com.fq包下的所有子类,不包含@Controller。对于exculude-filter不存在包不精确后都进行扫描的问题。

spring中的context:include-filter和context:exclude-filter的区别

原文:http://www.cnblogs.com/antis/p/7267026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!