1.38 context:exclude-filter标签

戴着假发的程序员出品

[查看视频教程]

我们已经知道context:component-scan的配置可以通知spring扫描拥有spring标准注解的类。这些标注大致是:@Component、@Controller、@Service、@Repository。我们也可通过context:exclude-filter标签配置排除我们不希望spring容器加载的类。

比如我们再web工程中只希望加载@Controller,就可以排除其他的标准注解的类。

这个标签和context:include-filter 都是context:component-scan的自标签,作用和context:include-filter正好相反,用于排除类。 但是配置方式和context:include-filter完全一样,同样有5个类型:

有两个必须的属性:

type: 配置filter的类型,这个类型一共有以下五个值:

assignable-指定扫描某个接口派生出来的类

annotation-指定扫描使用某个注解的类

aspectj-指定扫描AspectJ表达式相匹配的类

custom-指定扫描自定义的实现了

org.springframework.core.type.filter.TypeFilter接口的类

regex-指定扫描符合正则表达式的类

expression: 根据type的不同,这个表达式的配置方式也不同。

具体的案例可以参考context:include-filter章节。

posted @ 2020-10-06 09:29  戴着假发的程序员0-1  阅读(1667)  评论(0编辑  收藏  举报