@ComponentScan.Filter type的类型
生活随笔
收集整理的這篇文章主要介紹了
@ComponentScan.Filter type的类型
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
a)注解形式的FilterType.ANNOTATION @Controller @Service @Repository @Compent
b)指定類型的 FilterType.ASSIGNABLE_TYPE @ComponentScan.Filter(type =
FilterType.ASSIGNABLE_TYPE,value = {TulingService.class})
c)aspectj類型的 FilterType.ASPECTJ(不常用)
d)正則表達(dá)式的 FilterType.REGEX(不常用)
e)自定義的 FilterType.CUSTOM
public enum FilterType {//注解形式 比如@Controller @Service @Repository @Compent ANNOTATION,//指定的類型 ASSIGNABLE_TYPE,//aspectJ形式的 ASPECTJ,//正則表達(dá)式的 REGEX,//自定義的 CUSTOM}FilterType.CUSTOM 自定義類型如何使用
public class CustomFilterType implements TypeFilter {@Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {//獲取當(dāng)前類的注解源信息AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();//獲取當(dāng)前類的class的源信息ClassMetadata classMetadata = metadataReader.getClassMetadata();//獲取當(dāng)前類的資源信息Resource resource = metadataReader.getResource();if(classMetadata.getClassName().contains("dao")) {return true;}return false;} }@ComponentScan(basePackages = {"com.leon.testcompentscan"},includeFilters = { @ComponentScan.Filter(type = FilterType.CUSTOM,value = CustomFilterType.class) },useDefaultFilters = false) public class MainConfig {}?
總結(jié)
以上是生活随笔為你收集整理的@ComponentScan.Filter type的类型的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 包含用法 includeFilters
- 下一篇: 配置Bean的作用域对象