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 ype.filter.AnnotationTypeFilter
*/
ANNOTATION,
/**
* Filter candidates assignable to a given type.
* @see ype.filter.AssignableTypeFilter
*/
ASSIGNABLE_TYPE,
/**
* Filter candidates matching a given AspectJ type pattern expression.
* @see ype.filter.AspectJTypeFilter
*/
适合新手的spring boot
ASPECTJ,
/**
* Filter candidates matching a given regex pattern.
* @see ype.filter.RegexPatternTypeFilter
*/
REGEX,
/** Filter candidates using a given custom
* {@link ype.filter.TypeFilter} implementation.
*/
CUSTOM
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论