zoukankan      html  css  js  c++  java
  • springboot启动时过滤不需要注入的类

    在springbootApplication启动类上加入注解

    @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = XX.class))

     

    public @interface ComponentScan {
        .....................
        /**
         * Specifies which types are not eligible for component scanning.
         * @see #resourcePattern
         */
        Filter[] excludeFilters() default {};
    
        .........................
        /**
         * Declares the type filter to be used as an {@linkplain ComponentScan#includeFilters
         * include filter} or {@linkplain ComponentScan#excludeFilters exclude filter}.
         */
        @Retention(RetentionPolicy.RUNTIME)
        @Target({})
        @interface Filter {
    
            /**
             * The type of filter to use.
             * <p>Default is {@link FilterType#ANNOTATION}.
             * @see #classes
             * @see #pattern
             */
            FilterType type() default FilterType.ANNOTATION;
            ...........................
        }
    }

    其中@ComponentScan 注解属性excludeFilters可以过滤多个类型的类的加载,其中有内部类,可以指定过滤的类型,上面是指定class文件进行过滤,也可以指定其他类型的

    public enum FilterType {
    
        /**
         * Filter candidates marked with a given annotation.
         * @see org.springframework.core.type.filter.AnnotationTypeFilter
         */
        ANNOTATION,
    
        /**
         * Filter candidates assignable to a given type.
         * @see org.springframework.core.type.filter.AssignableTypeFilter
         */
        ASSIGNABLE_TYPE,
    
        /**
         * Filter candidates matching a given AspectJ type pattern expression.
         * @see org.springframework.core.type.filter.AspectJTypeFilter
         */
        ASPECTJ,
    
        /**
         * Filter candidates matching a given regex pattern.
         * @see org.springframework.core.type.filter.RegexPatternTypeFilter
         */
        REGEX,
    
        /** Filter candidates using a given custom
         * {@link org.springframework.core.type.filter.TypeFilter} implementation.
         */
        CUSTOM
    
    }
  • 相关阅读:
    js 整站模式窗口打开
    WebDev.WebServer 学习
    AjaxPro.2.dll基本使用
    jQuery.get(url,[data],[callback])
    ASP.NET CheckBoxList复选框
    Win7开发系列: windows服务操作基础
    .NET Remoting开发系列:(三) Remoting服务发布方式
    mysql 视图操作和存储过程
    Flash Lite1.1错误代码表
    myeclipse svn 清除缓存用户和密码
  • 原文地址:https://www.cnblogs.com/lantuanqing/p/10197338.html
Copyright © 2011-2022 走看看