java - How to find all controllers in Spring MVC? -
to provide runtime generated api documentation want iterate on spring mvc controllers. controllers annotated spring @controller annotation. this:
for (final object bean: this.context.getbeanswithannotation( controller.class).values()) { ...generate controller documentation bean... } but first call of code extremely slow. wonder if spring iterates on all classes in classpath instead of checking defined beans. controllers loaded when above code run, log displays of them request mappings spring mvc must know them , there must faster way list of them. how?
i have came across such requirement before months , have achieved using following code snippet.
classpathscanningcandidatecomponentprovider scanner = new classpathscanningcandidatecomponentprovider(false); scanner.addincludefilter(new annotationtypefilter(controller.class)); (beandefinition beandefinition : scanner.findcandidatecomponents("com.xxx.yyy.controllers")){ system.out.println(beandefinition.getbeanclassname()); } you can controllers.
updated code snippet. removed not necessary code , displaying class name of controllers better understanding. hope helps you. cheers.
Comments
Post a Comment