zoukankan      html  css  js  c++  java
  • 关于 spring MVC 配置自动扫描中 use-default-filters 属性

    1、springMVC 设置扫描 Bean 的两种常见写法

         1.1、先看第一种常见的配置:默认

    <!-- 配置Controller扫描 -->
    <context:component-scan base-package="com.jeenotes.ssm" />

        1.2、第二种,自定义,只扫描 control

    <!-- 使用Annotation自动注册Bean,只扫描@Controller -->
    <context:component-scan base-package="com.jeenotes.ssm" 
            use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 -->
         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

     

    2、use-default-filters="false"

        1.1 中默认情况下,该属性是 true ,作用就是:是否自动扫描带有 @Component、@Repository、@Service 和 @Controller 的类;
     
        1.2 中如果把该属性设置成 false,那么就可以自定义过滤要扫描的 Bean
     
    //这种写法是:去扫描某某某注解的 bean
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
     
    //这种写法是:不去扫描某某注解的 bean
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>

     

    3、补充:添加 && 排除      

         如果添加和排除的是相同,则必须 include-filter 在前,exclude-filter 在后,否则配置不符合 spring -context-3.0.xsd 要求,Spring容器解析时会出错。
     
     上面的配置会把@Repository注解的类排除掉。
     
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
        
        博客地址:http://www.cnblogs.com/niceyoo
     
  • 相关阅读:
    SpringBoot 项目 打包为 Docker镜像
    0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
    注册k8s到rancher时 agent pods一直处于containercreating状态
    linux查看磁盘使用情况
    linux修改系统时间、时区
    windows 添加路由
    Notebook Docker 安装spark环境
    openlayers6加载天地图混乱问题
    Oracle 高效分页
    VSCode 终端无法打开
  • 原文地址:https://www.cnblogs.com/niceyoo/p/9281564.html
Copyright © 2011-2022 走看看