Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Sep 11, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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().

  2. added
    type: enhancement
    in: web
    on Jan 11, 2019
  3. added this to the 4.2.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions