组件注册-自定义TypeFilter指定过滤规则

指定  type= FilterType.CUSTOM  来实现自定义过滤规则

@ComponentScan(value = "com.yyc", includeFilters ={@ComponentScan.Filter(type= FilterType.CUSTOM, classes={MyTypeFilter.class})} )

创建一个实现TypeFilter接口的类,来自定义过滤规则。false代表不通过,不进行bean的创建

public class MyTypeFilter implements TypeFilter {

    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {

        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

        ClassMetadata classMetadata = metadataReader.getClassMetadata();

        Resource resource = metadataReader.getResource();

        String className = classMetadata.getClassName();

        System.out.println("---->" + className);
        return false;
    }
}

 

posted on 2019-05-23 15:26  星辰钟塔的玛利亚女士  阅读(263)  评论(0编辑  收藏  举报

导航