Spring教程
ComponentScan注解用于指定扫描的路径,可以通过excludeFilters,includeFilters分别排除或包含部分组件
1、excludeFilters
package spring.example.anno; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; import org.springframework.stereotype.Service; @Configuration @ComponentScan(value = {"spring.example.anno.user", "spring.example.anno.item"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = {Service.class})}) public class Config { }
输出结果:
config userController userDao itemController itemDaoService注解的bean被排除在外
@ComponentScan.Filter type属性用于指定过滤时使用的类型,包括以下几种
FilterType.ANNOTATION :注解类型
FilterType.ASSIGNABLE_TYPE:具体的类
FilterType.ASPECTJ
FilterType.REGEX
FilterType.CUSTOM