成品超市网站,西丽网站设计,北京it公司排名,建筑360网文章目录 需求一、使用 ComponentScan 需求 在系统迭代的过程中#xff0c;有一些 Controller 大批量的不再使用#xff0c;或者有一些接口我们不想再提供给外界 一、使用 ComponentScan
SpringBootApplication(scanBasePackages com.zrb.excludeSomePkg)
Comp… 文章目录 需求一、使用 ComponentScan 需求 在系统迭代的过程中有一些 Controller 大批量的不再使用或者有一些接口我们不想再提供给外界 一、使用 ComponentScan
SpringBootApplication(scanBasePackages com.zrb.excludeSomePkg)
ComponentScan(basePackages com.zrb.excludeSomePkg,// 排除的过滤器excludeFilters {// 一种是自定义过滤, 一种是按照正则进行过滤ComponentScan.Filter(type FilterType.CUSTOM, classes CustomExcludeFilter.class),ComponentScan.Filter(type FilterType.REGEX, pattern com.zrb.*.*02)}
)
public class SpringBootAnnoExample {public static void main(String[] args) {ConfigurableApplicationContext applicationContext SpringApplication.run(SpringBootAnnoExample.class);Pk1Service bean1 applicationContext.getBean(Pk1Service.class);Pk2Service bean2 applicationContext.getBean(Pk2Service.class);System.out.println(bean2);System.out.println(bean1);}
}
public class CustomExcludeFilter implements TypeFilter {/*** 忽略pk1包下的所有类*/Overridepublic boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {String className metadataReader.getClassMetadata().getClassName();return className.startsWith(com.zrb.excludeSomePkg.pk1);}
}