title: How to find all controllers in Spring MVC?
body: <p>To provide some runtime generated API documentation I want to iterate over all Spring MVC controllers. All controllers are annotated with the Spring @Controller annotation. Currently I do it like this:</p>
  
  <pre><code>for (final Object bean: this.context.getBeansWithAnnotation(
          Controller.class).values())
  {
      ...Generate controller documentation for the bean...
  }
  </code></pre>
  
  <p>But the first call of this code is <strong>EXTREMELY</strong> slow. I wonder if Spring iterates over <strong>ALL</strong> classes in the classpath instead of just checking the defined beans. The controllers are already loaded when the above code is run, the log displays all of them with their request mappings so Spring MVC must already know them all and there must be a faster way to get a list of them. But how?</p>