http://jinnianshilongnian.iteye.com/blog/1762632

http://blog.51cto.com/wenshengzhu/1700340

http://www.cnblogs.com/kevin-yuan/p/5068448.html

【转载】https://www.cnblogs.com/haoke/p/4604883.html

在Spring MVC中的配置中一般会遇到这两个标签,作为<context:component-scan>的子标签出现。

存疑:

context:include-filter对于include,  除了扫描base-package包下面的子类,还扫描expression后面的包。
context:exclude-filter对于exclude,即使expression后面的包在base-package下面,也不扫描。

但在使用时要注意一下几点:

1.在很多配置中一般都会吧Spring-common.xml和Spring-MVC.xml进行分开配置,这种配置就行各施其职一样,显得特别清晰。

在Spring-MVC.xml中只对@Controller进行扫描就可,作为一个控制器,其他的事情不做。

在Spring-common.xml中只对一些事务逻辑的注解扫描。

2.现在给定一个项目包的机构:

com.fq.controlller

com.fq.service

就先给定这两个包机构

(1)在Spring-MVC.xml中有以下配置:

<!-- 扫描@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-common.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:component-scan base-package="com.alimama">
<!-- 不扫描com.alimama.trace包-->
<context:exclude-filter type="regex" expression="com.alimama.trace.*"/>
</context:component-scan>

【SpringMVC】<context:include-filter>和<context:exclude-filter>使用时要注意的地方的更多相关文章

  1. <context:component-scan>子标签:<context:include-filter>和<context:exclude-filter>使用时要注意的地方

    在Spring MVC中的配置中一般会遇到这两个标签,作为<context:component-scan>的子标签出现. 但在使用时要注意一下几点: 1.在很多配置中一般都会吧Spring ...

  2. Web.xml详解(转)(Filter,context,listener)

    web.xml 详细解释!!(链接) web.xml加载过程(步骤) 首先简单说一下,web.xml的加载过程. 当我们去启动一个WEB项目时,容器包括(JBoss.Tomcat等)首先会读取项目we ...

  3. Spring Security 入门(1-6-2)Spring Security - 内置的filter顺序、自定义filter、http元素和对应的filterChain

    Spring Security 的底层是通过一系列的 Filter 来管理的,每个 Filter 都有其自身的功能,而且各个 Filter 在功能上还有关联关系,所以它们的顺序也是非常重要的. 1.S ...

  4. 元素 "context:component-scan" 的前缀 "context" 未绑定的解决方案

    在动态web项目(Dynamic Web Project)中,使用SpringMVC框架,新建Spring的配置文件springmvc.xml,添加扫描控制器 <context:componen ...

  5. context:component-scan" 的前缀 "context" 未绑定。

    SpElUtilTest.testSpELLiteralExpressiontestSpELLiteralExpression(cn.zr.spring.spel.SpElUtilTest)org.s ...

  6. Android中,Context,什么是Context?

    注:本文翻译自Context, What Context?,原文链接在这里,作者是Dave Smith.ps:译者链接http://blog.csdn.net/race604/article/deta ...

  7. Android开发之Android Context,上下文(Activity Context, Application Context)

    转载:http://blog.csdn.net/lmj623565791/article/details/40481055 1.Context概念Context,相信不管是第一天开发Android,还 ...

  8. System.Drawing.Design.UITypeEditor自定义控件属性GetEditStyle(ITypeDescriptorContext context),EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  9. Spring context:component-scan中使用context:include-filter和context:exclude-filter

    Spring context:component-scan中使用context:include-filter和context:exclude-filter XML: <?xml version= ...

随机推荐

  1. Mybatis入门程序

    作为一个java的学习者,我相信JDBC是大家最早接触也是入门级别的数据库连接方式,所以我们先来回忆一下JDBC作为一种用于执行SQL语句的Java API是如何工作的.下面的一段代码就是最基本的JD ...

  2. jq 滚轮监听事件

    windowAddMouseWheel(); function windowAddMouseWheel() { var i = 0; var scrollFunc = function (e) { e ...

  3. html5shiv.js和respond.min.js的作用

    html5shiv:解决ie9以下浏览器对html5新增标签的不识别,并导致CSS不起作用的问题. respond.min:让不支持css3 Media Query的浏览器包括IE6-IE8等其他浏览 ...

  4. OAuth2.0学习(1-13)oauth2.0 的概念:资源、权限(角色)和scope

    mkk 关于资源的解释 : https://andaily.com/blog/?cat=19 resource用于将系统提供的各类资源进行分组管理, 每一个resource对应一个resource-i ...

  5. gradle入门(1-3)使用gradle开发一个发布版本

    需求描述 1.使用Maven central仓库.2.使用Log4j写入日志.3.包含单元测试,保证正确的信息返回,单元测试必须使用JUnit编写.4.创建一个可执行的Jar文件. 我们来看一下怎样实 ...

  6. 赛码网算法: 上台阶 ( python3实现 、c实现)

    上台阶 题目描述 有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第m级,共有多少走法?注:规定从一级到一级有0种走法. 输入输入数据首先包含一个整数n(1<=n<=1 ...

  7. spring cloud zipkin sleuth与spring boot aop结合后,启动慢

    问题描述: 引入了spring cloud的监控starter,间接引入jooq. 又引入了 spring-boot-starter-web,所以间接引入aop. 参考下面资料后:https://gi ...

  8. 1028阿里RDS如何恢复云数据库MySQL的备份文件到自建数据库

    参照 https://help.aliyun.com/knowledge_detail/41817.html 恢复云数据库MySQL的备份文件到自建数据库 更新时间:2017-07-27 14:52: ...

  9. Testlink1.7.5安装部署

    Testlink1.7.5安装部署 1   下载安装wamp5:下载地址:http://www.duote.com/soft/56016.html wamp5是apache.mysql.PHP的集成环 ...

  10. Java面试题1--关键字

    1. final关键字有哪些用法? 修饰类.方法和变量. (1) final变量是只读的,不允许改变其引用,与static共用可声明常量.JVM会对final变量进行优化,比如常量折叠. (2) fi ...