import io.github.classgraph.AnnotationInfo;
import io.github.classgraph.AnnotationInfoList;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;
public class AnnotationDetectorExample {
public static void main(String[] args) {
try (ScanResult scanResult = new ClassGraph().whitelistPackages("com.example").enableAllInfo().scan()) {
ClassInfoList classInfoList = scanResult.getClassesWithAnnotation("com.example.MyAnnotation");
for (ClassInfo classInfo : classInfoList) {
AnnotationInfoList annotationInfoList = classInfo.getAnnotationInfo();
for (AnnotationInfo annotationInfo : annotationInfoList) {
System.out.println("Found annotation: " + annotationInfo.getName());
}
}
}
}
}
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.118</version>
</dependency>