zoukankan      html  css  js  c++  java
  • spring 排除指定的类或者包扫描

    <!-- 排除Controller注解的扫描 -->
    <context:component-scan base-package="exampleBean">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
    
    
    <!-- 排除扫描符合正则表达式的类,此处排除com.wx.comm.util包下的所有类 -->
    <context:component-scan base-package="exampleBean">
        <context:exclude-filter type="regex"
            expression="com.wx.comm.util.*" />
    </context:component-scan>
    
    
    <!-- 排除指定包exampleBean下的CommFF类的扫描 -->
    <context:component-scan base-package="exampleBean">
        <context:exclude-filter type="assignable"
            expression="exampleBean.CommFF" />
    </context:component-scan>

    参考:https://docs.spring.io/spring/docs/4.3.12.RELEASE/spring-framework-reference/htmlsingle/

    7.10.4 Using filters to customize scanning

    By default, classes annotated with @Component@Repository@Service@Controller, or a custom annotation that itself is annotated with @Component are the only detected candidate components. However, you can modify and extend this behavior simply by applying custom filters. Add them as includeFilters or excludeFiltersparameters of the @ComponentScan annotation (or as include-filter or exclude-filter sub-elements of the component-scan element). Each filter element requires the type and expression attributes. The following table describes the filtering options.

    Filter TypeExample ExpressionDescription

    annotation (default)

    org.example.SomeAnnotation

    An annotation to be present at the type level in target components.

    assignable

    org.example.SomeClass

    A class (or interface) that the target components are assignable to (extend/implement).

    aspectj

    org.example..*Service+

    An AspectJ type expression to be matched by the target components.

    regex

    org.example.Default.*

    A regex expression to be matched by the target components class names.

    custom

    org.example.MyTypeFilter

    A custom implementation of the org.springframework.core.type .TypeFilter interface.

    The following example shows the configuration ignoring all @Repository annotations and using "stub" repositories instead.

    @Configuration
    @ComponentScan(basePackages = "org.example",
            includeFilters = @Filter(type = FilterType.REGEX, pattern = ".*Stub.*Repository"),
            excludeFilters = @Filter(Repository.class))
    public class AppConfig {
        ...
    }
  • 相关阅读:
    python基础篇 08 文件操作
    python基础篇 07set集合 深浅拷贝
    python 基础篇 06 编码 以及小知识点补充
    python基础篇 05字典
    钉钉中设置代码提交提醒--Github机器人(转)
    Spring Boot 之FilterRegistrationBean --支持web Filter 排序的使用(转)
    Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置(转)
    为什么添加了@Aspect 还要加@Component(转)
    Servlet 服务器 HTTP 响应
    Servlet 客户端 HTTP 请求
  • 原文地址:https://www.cnblogs.com/815346909/p/10330058.html
Copyright © 2011-2022 走看看