1、<!-- 启用注解扫描,并定义组件查找规则 ,mvc层只负责扫描@Controller -->

[java] view plain copy

  1. <context:component-scan base-package="com.nn.web.controller"
  2. use-default-filters="false">
  3. <context:include-filter type="annotation"
  4. expression="org.springframework.stereotype.Controller" />
  5. </context:component-scan>

2、在context:component-scan可以添加use-default-filters,spring配置中的use-default-filters用来指示是否自动扫描带有@Component、@Repository、@Service和@Controller的类。默认为true,即默认扫描。

3、如果想要过滤其中这四个注解中的一个,比如@Repository,可以添加<context:exclude-filter />子标签:

[java] view plain copy

  1. <context:component-scan base-package="tv.crm" scoped-proxy="targetClass" use-default-filters="true">
  2. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
  3. </context:component-scan>

4、而<context:include-filter/>子标签是用来添加扫描注解的。

[java] view plain copy

  1. <context:component-scan base-package="tv.crm" scoped-proxy="targetClass" use-default-filters="false">
  2. <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
  3. </context:component-scan>

5、但是如果添加和排除的是相同,则必须include-filter在前,exclude-filter在后,否则配置不符合spring -context-3.0.xsd要求,Spring容器解析时会出错。上面的配置会把@Repository注解的类排除掉。

[java] view plain copy

  1. <span style="font-size:18px;"><context:component-scan base-package="tv.crm" scoped-proxy="targetClass" use-default-filters="false">
  2. <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
  3. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
  4. </context:component-scan></span>

springmvc-servlet.xml中use-default-filters的作用的更多相关文章

  1. SpringMVC: web.xml中声明DispatcherServlet时一定要加入load-on-startup标签

    游历SpringMVC源代码后发现,在web.xml中注冊的ContextLoaderListener监听器不过初始化了一个根上下文,只完毕了组件扫描和与容器初始化相关的一些工作,并没有探測到详细每一 ...

  2. SpringMVC: web.xml中声明DispatcherServlet时一定要添加load-on-startup标签

    游历SpringMVC源码后发现,在web.xml中注册的ContextLoaderListener监听器只是初始化了一个根上下文,仅仅完成了组件扫描和与容器初始化相关的一些工作,并没有探测到具体每个 ...

  3. Tomcat配置文件之servlet.xml中选项介绍

    Servlet.xml 分为以下元素: server, service, Connector ( 表示客户端和service之间的连接), Engine ( 表示指定service 中的请求处理机,接 ...

  4. ()-servlet.xml中剥离出的hibernate.cfg.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. web.xml中<welcome-file-list>标签不起作用

    之前也都提到过,web.xml会通过<servlet>和<servlet-mapping>来确定url和指定contoller文件,乃至于jsp页面的联系. 但是有一个< ...

  6. web.xml中的welcome-file-list不起作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

  7. maven pom.xml 中各个标签元素的作用

    <groupId> : 项目或者组织的唯一标识 <artifactId>项目的通用名称 <artifactId>项目的通用名称 <version> 项目 ...

  8. SpringMVC(十六):如何使用编程方式替代/WEB-INF/web.xml中的配置信息

    在构建springmvc+mybatis项目时,更常用的方式是采用web.xml来配置,而且一般情况下会在web.xml中使用ContextLoaderListener加载applicationCon ...

  9. 【Servlet】web.xml中welcome-file-list的作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

  10. web.xml中welcome-file-list的作用

    今天尝试使用struts2+ urlrewrite+sitemesh部署项目,结果发现welcome-file-list中定义的欢迎页不起作用: <welcome-file-list> & ...

随机推荐

  1. Delphi 设置快捷键

    = 'Repeat %s(&' + #32 + ')';  //设置快捷键  这个是设置空格的  如果设置字符,  就可以这样写= 'Repeat %s(&H)‘ const SRep ...

  2. [Node.js]连接mongodb

    摘要 前面介绍了node.js操作mysql以及redis的内容,这里继续学习操作mongodb的内容. 安装驱动 安装命令 cnpm install mongodb 安装成功 数据库操作 因为mon ...

  3. C#编程(三十五)----------foreach和yield

    枚举 在foreach语句中使用枚举,可以迭代集合中的元素,且无需知道集合中的元素个数. 数组或集合实现带GetEumerator()方法的IEumerable接口.GetEumerator()方法返 ...

  4. 【mybatis】mybatis进行批量更新,报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right

    使用mybatis进行批量更新操作: 报错如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an erro ...

  5. Ubuntu 14.04 用户如何安装 VLC 2.2.0

    http://www.linuxidc.com/Linux/2014-03/98913.htm http://www.videolan.org/vlc/#download VLC 是一款自由开源.跨平 ...

  6. MySql、Oracle、MSSQL中的字符串的拼接

    字符串的拼接 1,Mysql 在Java.C#等编程语言中字符串的拼接可以通过加号“+”来实现,比如:"1"+"3"."a"+"b ...

  7. asp.net mvc5 安装

    原文地址 http://docs.nuget.org/docs/start-here/using-the-package-manager-console 工具-->NuGet程序包管理器--&g ...

  8. Android系统机制解析-公共服务

    创建一个公共服务类后有两种使用方式,第一种将公共服务放到自己的项目中执行,这样外界无法訪问和控制这个公共服务类.这个服务的全部变量.函数都在自己的项目中执行.能够直接通过startIntent(Ser ...

  9. Java并发编程的艺术(八)——闭锁、同步屏障、信号量详解

    1. 闭锁:CountDownLatch 1.1 使用场景 若有多条线程,其中一条线程需要等到其他所有线程准备完所需的资源后才能运行,这样的情况可以使用闭锁. 1.2 代码实现 // 初始化闭锁,并设 ...

  10. [Hook] 免root,自己进程内,binder hook (ClipboardManager)

    cp from : http://weishu.me/2016/02/16/understand-plugin-framework-binder-hook/ Android系统通过Binder机制给应 ...