import org.scannotation.ClasspathUrlFinder; import org.scannotation.AnnotationDB; public class ScannotationExample { public static void main(String[] args) throws Exception { String[] classUrls = ClasspathUrlFinder.findResourceBases(""); AnnotationDB annotationDB = new AnnotationDB(); annotationDB.scanArchives(classUrls); String[] annotatedClasses = annotationDB.getAnnotationIndex().get("com.example.MyAnnotation"); for (String className : annotatedClasses) { System.out.println("Found class with annotation: " + className); } } } <dependency> <groupId>org.scannotation</groupId> <artifactId>scannotation</artifactId> <version>1.0.3</version> </dependency>


上一篇:
下一篇:
切换中文