程序员社区

Spring配置之<context:include-filter/>和<context:exclude-filter/>详解

context:include-filter和context:exclude-filter

  • context:include-filter:指定扫描包时,不包含的类
    • type="annotation"
    • type="assignable"
  • context:exclude-filter:指定扫描包时,要包含的类,默认全部扫描进来
    • 一定要先禁用掉默认过滤规则
    • use-default-filters=false :将默认全部扫描的规则关闭,只选择自己想要的
    • type="annotation"
    • type="assignable"

context:include-filter:指定扫描包时,不包含的类

type=“annotation”

指定排除规则,按照注解进行排除,标注了指定注解的组件不要
expression="" :注解的全类名

  <context:component-scan base-package="com">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Component"/>
    </context:component-scan>

type=“assignable”

type=“assignable” : 指定排除某个具体的类,按照类排除
expression="" :类的全类名

    <context:component-scan base-package="com">
        <context:exclude-filter type="assignable" expression="com.dhy.Factory.main"/>
    </context:component-scan>

context:exclude-filter:指定扫描包时,要包含的类,默认全部扫描进来

一定要先禁用掉默认过滤规则

use-default-filters=false :将默认全部扫描的规则关闭,只选择自己想要的

type=“annotation”

指定排除规则,按照注解进行排除,标注了指定注解的组件不要
expression="" :注解的全类名

    <context:component-scan base-package="com" use-default-filters="false">
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
    </context:component-scan>

type=“assignable”

type=“assignable” : 指定排除某个具体的类,按照类排除
expression="" :类的全类名

    <context:component-scan base-package="com" use-default-filters="false">
      <context:include-filter type="assignable" expression="com.dhy.Factory.main"/>
    </context:component-scan>

赞(0) 打赏
未经允许不得转载:IDEA激活码 » Spring配置之<context:include-filter/>和<context:exclude-filter/>详解

相关推荐

  • 暂无文章

一个分享Java & Python知识的社区