Spring加載早期獲取BasePackage

public class GetBasePackage {
private Class<? extends Annotation> annotation;

public GetBasePackage(Class<? extends Annotation> annotation) {
this.annotation = annotation;
}

public Stream<String> getBasePackage(AnnotationMetadata annotationMetadata){
Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(annotation.getName());
AnnotationAttributes attributes = new AnnotationAttributes(annotationAttributes);
String[] value = attributes.getStringArray("value");//annotationg中的註解
String[] basePackages = attributes.getStringArray("basePackages");//annotationg中的註解
String[] entityPaths = attributes.getStringArray("entityPath");//annotationg中的註解
//沒配註解
if (value.length == 0 && basePackages.length == 0 && entityPaths.length == 0) {
String className = annotationMetadata.getClassName();
return Stream.of(ClassUtils.getPackageName(className));
}
//配了註解
return Stream.of(Arrays.asList(value),Arrays.asList(basePackages),Arrays.asList(entityPaths)).flatMap(list -> list.stream());
}
}
GetBasePackage getBasePackage = new GetBasePackage(EnableESTools.class);
getBasePackage.getBasePackage(annotationMetadata).forEach((s) -> {
    System.out.println(s);
});

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章