标签:play tin enum 判断 constant roc spl soft free
一、PathMatchingResourcePatternResolver
二、SimpleMetadataReaderFactory
三、实现(核心代码)
private static final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); private static final SimpleMetadataReaderFactory register = new SimpleMetadataReaderFactory(); //指定包路径 Resource[] resources = resolver.getResources("classpath*:com/rockcode/**/*.class"); for (int i = 0; i < resources.length; i++) { Resource resource = resources[i]; MetadataReader metadataReader = register.getMetadataReader(resource); //读取资源的注解配置 AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); //判断是否包含注解 例如:@A 注解 if (!annotationMetadata.hasAnnotation(A.class.getName())) continue; //类信息 获取所有包含 @A 注解的类信息 ClassMetadata classMetadata = metadataReader.getClassMetadata();
//类全名
String className = classMetadata.getClassName();
//加载类
Class<?> clazz = Class.forName(className);
//如果是枚举,获取所有枚举值
Enum[] freezeBoxStates = (Enum[]) clazz.getEnumConstants();
}
标签:play tin enum 判断 constant roc spl soft free
原文地址:https://www.cnblogs.com/xums/p/12377256.html