<dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.9.11</version> </dependency> <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>25.1-jre</version> </dependency>
Reflections reflections = new Reflections("com.fangfa.jiliang.controller"); Set<Class<?>> classesList = reflections.getTypesAnnotatedWith(Controller.class); for(Class clazz : classesList) { Annotation[] annotationsByType = clazz.getAnnotationsByType(Controller.class); for (Annotation a:annotationsByType) { Controller c = (Controller)a; System.out.println(c.value()); } }