public static < T extends Annotation > Method findMethodWithAnnotation ( Class < ? > clazz , Class < T > annotationType ) { Method annotatedMethod = null ; for ( Method method : clazz . getDeclaredMethods ( ) ) { T annotation = AnnotationUtils . findAnnotation ( method , annotationType ) ; if ( annotation != null ) { if ( annotatedMethod != null ) { throw new BeanCreationException ( "Only ONE method with @" + annotationType . getName ( ) + " is allowed on " + clazz . getName ( ) + "." ) ; } annotatedMethod = method ; } } if ( ( annotatedMethod != null ) || clazz . equals ( Object . class ) ) { return annotatedMethod ; } else { return findMethodWithAnnotation ( clazz . getSuperclass ( ) , annotationType ) ; } }
Finds a method annotated with the specified annotation . This method can be defined in the specified class or one of its parents .