title: Find method level custom annotation in a Spring context
body: <p>All I wanted to find out was "all the class/methods in <a href="http://en.wikipedia.org/wiki/Spring_Framework" rel="noreferrer">Spring</a> beans which are annotated as @Versioned".</p>
  
  <p>I created my custom annotation as,</p>
  
  <pre><code>@Target({ElementType.METHOD, ElementType.TYPE})
  @Retention(RetentionPolicy.RUNTIME)
  @Documented
  public @interface Versioned {
      .....
  }
  </code></pre>
  
  <p>This annotation <strong>works perfectly</strong> when I use Java reflection to find methods as:</p>
  
  <pre><code>for(Method m: obj.getClass().getMethods()){
      if(m.isAnnotationPresent(Versioned.class)){
          .... // Do something
      }
  </code></pre>
  
  <p>But it does not work when I access Spring beans and try similar check:</p>
  
  <pre><code>public class VersionScanner implements ApplicationContextAware{
      public void setApplicationContext(ApplicationContext applicationContext){
          for(String beanName: applicationContext.getBeanDefinitionNames()){
              for(Method m: applicationContext.getBean(beanName).getClass().getDeclaredMethods()){
                  if(m.isAnnotationPresent(Versioned.class){
                      // This is not WORKING as expected for any beans with method annotated
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>In fact, this code does find other annotations such as @RequestMapping. I am not sure what I am doing wrong with my custom annotation.</p>