赞
踩
maven 依赖 <!-- https://mvnrepository.com/artifact/io.github.classgraph/classgraph --> <dependency> <groupId>io.github.classgraph</groupId> <artifactId>classgraph</artifactId> <version>4.4.12</version> </dependency> 作用: 1.扫描指定包下的类的所有信息,如类,注解,方法... 简单使用: ```java { // 1.指定扫描的结果类型,与包的位置 ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages("com.tbc.gkk.*").scan(); // 2.获取扫描到的所有的class信息 ClassInfoList allClasses = scanResult.getAllClasses(); // 3.遍历获取每一个class的详细信息 for (ClassInfo allClass : allClasses) { //获取注解集合 ClassInfoList annotations = allClass.getAnnotations(); //获取方法集合 MethodInfoList methodInfo = allClass.getMethodInfo(); //获取类名称 String name = allClass.getName(); //获取注解默认值 AnnotationParameterValueList annotationDefaultParameterValues = allClass.getAnnotationDefaultParameterValues(); /** * 以上为示例,方法中还可可以获取方法的相关信息,注解也一样 */ } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。