spring注解排除某些bean

2023-12-29 10:06:13 浏览数 (2)

劳动是唯一导向知识的道路。——萧伯纳

使用:

代码语言:javascript复制
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
        value = {WillExludeBean.class, AnotherWillExludeBean.class})})

即可

这里还有其他的过滤类型

例如注解

代码语言:javascript复制
@ComponentScan(excludeFilters = @Filter(
    type = FilterType.ANNOTATION,
    value = Service.class))

切面

代码语言:javascript复制
@ComponentScan(includeFilters = @Filter(
    type = FilterType.ASPECTJ,
    pattern = "com.example..*Service "))

正则

代码语言:javascript复制
@ComponentScan(includeFilters = @Filter(
    type = FilterType.REGEX,
    pattern = "com\.example\..*Service"))

0 人点赞