You can achieve this by using Google Guava and Java Reflection API.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
Google Guava includes a class ClassPath with three methods to scan for top level classes, in that you can use getTopLevelClasses(String packageName)
Refer this example code.
public void getClassOfPackage(String packagenom) {
final ClassLoader loader = Thread.currentThread()
.getContextClassLoader();
try {
ClassPath classpath = ClassPath.from(loader); // scans the class path used by classloader
for (ClassPath.ClassInfo classInfo : classpath.getTopLevelClasses(packagenom)) {
if(!classInfo.getSimpleName().endsWith("_")){
System.out.println(classInfo.getSimpleName());
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
Below code will print all @RequestMapping from a single controller, you can update this code.
Class clazz = Class.forName("com.abc.cbe.rest.controller.MyController"); // or list of controllers, //you can iterate that list
for(Method method :clazz.getMethods()){
for(Annotation annotation :method.getDeclaredAnnotations()){
if(annotation.toString().contains("RequestMapping"))
System.out.println("Annotation is..."+ annotation.toString());
}
}