spring-framework / org.springframework.core.annotation

Package org.springframework.core.annotation

Types

AnnotatedElementUtils

open class AnnotatedElementUtils

General utility methods for finding annotations, meta-annotations, and repeatable annotations on AnnotatedElement.

AnnotatedElementUtils defines the public API for Spring's meta-annotation programming model with support for annotation attribute overrides. If you do not need support for annotation attribute overrides, consider using AnnotationUtils instead.

Note that the features of this class are not provided by the JDK's introspection facilities themselves.

Annotation Attribute Overrides

Support for meta-annotations with attribute overrides in composed annotations is provided by all variants of the getMergedAnnotationAttributes(), getMergedAnnotation(), getAllMergedAnnotations(), getMergedRepeatableAnnotations(), findMergedAnnotationAttributes(), findMergedAnnotation(), findAllMergedAnnotations(), and findMergedRepeatableAnnotations() methods.

Find vs. Get Semantics

The search algorithms used by methods in this class follow either find or get semantics. Consult the javadocs for each individual method for details on which search algorithm is used.

Get semantics are limited to searching for annotations that are either present on an AnnotatedElement (i.e., declared locally or java.lang.annotation.Inherited) or declared within the annotation hierarchy above the AnnotatedElement.

Find semantics are much more exhaustive, providing get semantics plus support for the following:

  • Searching on interfaces, if the annotated element is a class
  • Searching on superclasses, if the annotated element is a class
  • Resolving bridged methods, if the annotated element is a method
  • Searching on methods in interfaces, if the annotated element is a method
  • Searching on methods in superclasses, if the annotated element is a method
Support for @Inherited

Methods following get semantics will honor the contract of Java's java.lang.annotation.Inherited annotation except that locally declared annotations (including custom composed annotations) will be favored over inherited annotations. In contrast, methods following find semantics will completely ignore the presence of @Inherited since the find search algorithm manually traverses type and method hierarchies and thereby implicitly supports annotation inheritance without the need for @Inherited.

OrderUtils

abstract class OrderUtils

General utility for determining the order of an object based on its type declaration. Handles Spring's Order annotation as well as javax.annotation.Priority.

SynthesizedAnnotation

interface SynthesizedAnnotation

Marker interface implemented by synthesized annotation proxies.

Used to detect whether an annotation has already been synthesized.

SynthesizingMethodParameter

open class SynthesizingMethodParameter : MethodParameter

A MethodParameter variant which synthesizes annotations that declare attribute aliases via AliasFor.

Annotations

Order

class Order

@Order defines the sort order for an annotated component.

The #value is optional and represents an order value as defined in the Ordered interface. Lower values have higher priority. The default value is Ordered.LOWEST_PRECEDENCE, indicating lowest priority (losing to any other specified order value).

NOTE: Since Spring 4.0, annotation-based ordering is supported for many kinds of components in Spring, even for collection injection where the order values of the target components are taken into account (either from their target class or from their @Bean method). While such order values may influence priorities at injection points, please be aware that they do not influence singleton startup order which is an orthogonal concern determined by dependency relationships and @DependsOn declarations (influencing a runtime-determined dependency graph).

Since Spring 4.1, the standard javax.annotation.Priority annotation can be used as a drop-in replacement for this annotation in ordering scenarios. Note that Priority may have additional semantics when a single element has to be picked (see AnnotationAwareOrderComparator#getPriority).

Alternatively, order values may also be determined on a per-instance basis through the Ordered interface, allowing for configuration-determined instance values instead of hard-coded values attached to a particular class.

Consult the javadoc for org.springframework.core.OrderComparator for details on the sort semantics for non-ordered objects.

Exceptions

AnnotationConfigurationException

open class AnnotationConfigurationException : NestedRuntimeException

Thrown by AnnotationUtils and synthesized annotations if an annotation is improperly configured.