-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Sam Brannen opened SPR-13440 and commented
Status Quo
Spring Framework 4.2 introduced support for explicit annotation attribute overrides via @AliasFor; however, due to historical reasons, the Spring code base typically uses the lookup methods in AnnotationUtils which do not support attribute overrides.
For example, although Spring MVC supports @RequestMapping as a merged annotation, the same is not true for @ResponseStatus. @ResponseStatus is in fact supported as a meta-annotation, just not as a merged annotation. This means that the responseStatus attribute override in the following custom composed @Post annotation is currently unsupported even though it is declared syntactically correct. Furthermore, use of the responseStatus will fail silently: it will simply be ignored (see #18021).
@RequestMapping(method = POST)
@ResponseStatus
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Post {
@AliasFor(annotation = RequestMapping.class, attribute = "path")
String[] value() default {};
@AliasFor(annotation = RequestMapping.class, attribute = "path")
String[] path() default {};
@AliasFor(annotation = ResponseStatus.class, attribute = "code")
HttpStatus responseStatus() default HttpStatus.CREATED;
}Deliverables
- Determine which annotations in the Spring Framework should be supported as merged annotations (i.e., support attribute overrides).
- Migrate from lookups in
AnnotationUtilsto methods such asfindAllMergedAnnotations(),findMergedAnnotation(), orgetMergedAnnotationinAnnotatedElementUtilswherever feasible.
Affects: 4.2 GA
Issue Links:
- Provide a mechanism for composed annotations to signal that they want to override attributes [SPR-13448] #18028 Provide a mechanism for composed annotations to signal that they want to override attributes
- Introduce predefined composed annotations in core Spring [SPR-13442] #18022 Introduce predefined composed annotations in core Spring
- Document Spring Annotation Programming Model in the Wiki [SPR-11515] #16140 Document Spring Annotation Programming Model in the Wiki
- Allow @Qualifier to be used in composed annotations with attribute overrides [SPR-14058] #18630 Allow
@Qualifierto be used in composed annotations with attribute overrides - Optimize ordered event listener performance [SPR-14642] #19208 Optimize ordered event listener performance
- Support @ResponseStatus as a merged composed annotation [SPR-13441] #18021 Support
@ResponseStatusas a merged composed annotation - Support @CrossOrigin as a merged composed annotation [SPR-13468] #18047 Support
@CrossOriginas a merged composed annotation - Support @Cache* as merged composed annotations [SPR-13475] #18054 Support
@Cache* as merged composed annotations - Support @AliasFor for @JmsListener attributes [SPR-13803] #18376 Support
@AliasForfor@JmsListenerattributes
Referenced from: commits 63115ed, c5b318a, 5025c61
0 votes, 5 watchers