zoukankan      html  css  js  c++  java
  • springmvc-servlet.xml中use-default-filters的作用

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

    [java] view plain copy
     在CODE上查看代码片派生到我的代码片
    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
     在CODE上查看代码片派生到我的代码片
    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
     在CODE上查看代码片派生到我的代码片
    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
     在CODE上查看代码片派生到我的代码片
    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>  






  • 相关阅读:
    韩式英语
    Daily dictation 听课笔记
    words with same pronunciation
    you will need to restart eclipse for the changes to take effect. would you like to restart now?
    glottal stop(britain fountain mountain)
    education 的发音
    第一次用Matlab 的lamada语句
    SVN的switch命令
    String的split
    SVN模型仓库中的资源从一个地方移动到另一个地方的办法(很久才解决)
  • 原文地址:https://www.cnblogs.com/jeffen/p/6397629.html
Copyright © 2011-2022 走看看