Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.core.annotation
Class AnnotationUtils

    java.lang.Object
      org.springframework.core.annotation.AnnotationUtils

    public abstract class AnnotationUtils

extends Object

General utility methods for working with annotations, handling bridge methods (which the compiler generates for generic declarations) as well as super methods (for optional "annotation inheritance"). Note that none of this is provided by the JDK's introspection facilities themselves.

As a general rule for runtime-retained annotations (e.g. for transaction control, authorization or service exposure), always use the lookup methods on this class instead of the plain annotation lookup methods in the JDK. You can still explicitly choose between lookup on the given class level only (`getAnnotation(java.lang.reflect.Method, java.lang.Class)`) and lookup in the entire inheritance hierarchy of the given method (`findAnnotation(java.lang.reflect.Method, java.lang.Class)`).

Since:
  2.0
Author:
  Rod Johnson, Rob Harrop, Juergen Hoeller
See Also:
  `AccessibleObject.getAnnotations()`, `Method.getAnnotation(Class)`

Constructor Summary
`AnnotationUtils()`

Method Summary
`static
`<A extends Annotation> A`
` | `findAnnotation(Method method, Class<A> annotationType)` Get a single `Annotation` of `annotationType` from the supplied `Method`, traversing its super methods if no annotation can be found on the given method.
`static
`<A extends Annotation> A`
` | `getAnnotation(Method method, Class<A> annotationType)` Get a single `Annotation` of `annotationType` from the supplied `Method`.
`static Annotation[]` | `getAnnotations(Method method)` Get all `Annotations` from the supplied `Method`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AnnotationUtils

    public AnnotationUtils()

Method Detail

### getAnnotations

    public static Annotation[] getAnnotations(Method method)

  Get all `Annotations` from the supplied `Method`.

  Correctly handles bridge `Methods` generated by the compiler.

  Parameters:
    `method` - the method to look for annotations on
  Returns:
    the annotations found
  See Also:
    `BridgeMethodResolver.findBridgedMethod(Method)`

### getAnnotation

    public static <A extends Annotation> A getAnnotation(Method method,
                                                         Class<A> annotationType)

  Get a single `Annotation` of `annotationType` from the supplied `Method`.

  Correctly handles bridge `Methods` generated by the compiler.

  Parameters:
    `method` - the method to look for annotations on
    `annotationType` - the annotation class to look for
  Returns:
    the annotations found
  See Also:
    `BridgeMethodResolver.findBridgedMethod(Method)`

### findAnnotation

    public static <A extends Annotation> A findAnnotation(Method method,
                                                          Class<A> annotationType)

  Get a single `Annotation` of `annotationType` from the supplied `Method`, traversing its super methods if no annotation can be found on the given method.

  Annotations on methods are not inherited by default, so we need to handle this explicitly.

  Parameters:
    `method` - the method to look for annotations on
    `annotationType` - the annotation class to look for
  Returns:
    the annotation of the given type found, or `null`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2007 The Spring Framework.