diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AliasFor.java b/spring-core/src/main/java/org/springframework/core/annotation/AliasFor.java index 337db773d1..3994bfac70 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AliasFor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AliasFor.java @@ -24,18 +24,120 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * TODO Document @AliasFor. + * {@code @AliasFor} is an annotation that is used to declare aliases for + * annotation attributes. + * + *

Usage Scenarios

+ * + * + *

Usage Requirements

+ *

Like with any annotation in Java, the mere presence of {@code @AliasFor} + * on its own will not enforce alias semantics. For alias semantics to be + * enforced, annotations must be loaded via the utility methods in + * {@link AnnotationUtils}. Behind the scenes, Spring will synthesize + * an annotation by wrapping it in a dynamic proxy that transparently enforces + * attribute alias semantics for annotation attributes that are + * annotated with {@code @AliasFor}. Similarly, {@link AnnotatedElementUtils} + * supports explicit meta-annotation attribute overrides when {@code @AliasFor} + * is used within an annotation hierarchy. Typically you will not need to + * manually synthesize annotations on your own since Spring will do that for + * you transparently when looking up annotations on Spring-managed components. + * + *

Implementation Requirements

+ * + * + *

Example: Aliases within an Annotation

+ *
 public @interface ContextConfiguration {
+ *
+ *    @AliasFor(attribute = "locations")
+ *    String[] value() default {};
+ *
+ *    @AliasFor(attribute = "value")
+ *    String[] locations() default {};
+ *
+ *    // ...
+ * }
+ * + *

Example: Alias for Attribute in Meta-annotation

+ *
 @ContextConfiguration
+ * public @interface MyTestConfig {
+ *
+ *    @AliasFor(annotation = ContextConfiguration.class, attribute = "locations")
+ *    String[] xmlFiles();
+ * }
+ * + *

Spring Annotations Supporting Attribute Aliases

+ *

As of Spring Framework 4.2, the following annotations within core + * Spring have been updated to use {@code @AliasFor} to configure their + * internal attribute aliases. + *

* * @author Sam Brannen * @since 4.2 + * @see AnnotatedElementUtils + * @see AnnotationUtils + * @see AnnotationUtils#synthesizeAnnotation(Annotation, java.lang.reflect.AnnotatedElement) + * @see SynthesizedAnnotation */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Documented public @interface AliasFor { + /** + * The name of the attribute that this attribute is an alias for. + */ String attribute(); + /** + * The type of annotation in which the aliased {@link #attribute} is declared. + *

Defaults to {@link Annotation}, implying that the aliased attribute is + * declared in the same annotation as this attribute. + */ Class annotation() default Annotation.class; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationConfigurationException.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationConfigurationException.java index b3317b1b6d..7e444d838b 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationConfigurationException.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationConfigurationException.java @@ -17,10 +17,13 @@ package org.springframework.core.annotation; /** - * Thrown by {@link AnnotationUtils} if an annotation is improperly configured. + * Thrown by {@link AnnotationUtils} and synthesized annotations + * if an annotation is improperly configured. * * @author Sam Brannen * @since 4.2 + * @see AnnotationUtils + * @see SynthesizedAnnotation */ @SuppressWarnings("serial") public class AnnotationConfigurationException extends RuntimeException {