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
     
  • 相关阅读:
    003_当表中字段不能为空,但却没有赋值时?
    019_SSM——mybatis的#{id}可以根据是对象参数调用setId()的原码?
    002_com.wkcto自动添加错误
    018_SSM——Spring框架的byName与ByType实现自动注入的原码是什么呢?
    as3 文档类引用
    as3 连接mysql
    as2 针对加载进来的swf操作
    as3 arguments.callee与... (rest)
    as3 string split方法一些注意
    as3 Function 中的call与apply方法
  • 原文地址:https://www.cnblogs.com/niceyoo/p/9281564.html
Copyright © 2011-2022 走看看