Skip to content

Support @ResponseStatus as a merged composed annotation [SPR-13441] #18021

Closed
@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-13441 and commented

Status Quo

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 attribute will fail silently: it will simply be ignored.

@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

  1. Look up @ResponseStatus using AnnotatedElementUtils.findMergedAnnotation() instead of AnnotationUtils.findAnnotation().

Affects: 4.2 GA

Issue Links:

Referenced from: commits e2bfbdc

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions