Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
spring-projects-issues opened this issue Sep 7, 2015 · 1 comment
Closed
1 task done
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 7, 2015

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

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Completed in GitHub commit e2bfbdc:

Support attribute overrides with @ResponseStatus

This commit introduces support for attribute overrides for @ResponseStatus when @ResponseStatus is used as a meta-annotation on a custom composed annotation.

Specifically, this commit migrates all code that looks up @ResponseStatus from using AnnotationUtils.findAnnotation() to using AnnotatedElementUtils.findMergedAnnotation().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants