Rob Winch opened SPR-17296 and commented

It would be nice if @RequestHeader could be used for a meta-annotation. This would make it easier if a header was being used consistently throughout the entire application. For example, a user might do something like this:

@Retention(RetentionPolicy.RUNTIME)
@RequestHeader(name = "user-id")
public @interface CurrentUserId {
}

No further details from SPR-17296

Comment From: joehitt

Please consider also doing this for @RequestParam, so same can be done for commonly-reused request parameters. A common use case would be page number and page size for Pageable REST services:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@RequestParam(name = "page", required = false)  //  currently "not applicable to annotation type"
public @interface PageNumber {
}

Comment From: sbrannen

Currently slated for 5.3.

We will need to assess whether such changes need to be applied to additional controller method argument annotations as well.

It may be sufficient to switch from MethodParameter to SynthesizingMethodParameter for such annotation lookups.

Comment From: sbrannen

It may be sufficient to switch from MethodParameter to SynthesizingMethodParameter for such annotation lookups.

I take that back. @RequestParam and @RequestHeader already make use of @AliasFor for attribute aliases within those annotations. Thus, SynthesizingMethodParameter (or a subclass thereof) is already in place.

In order to support these annotations as meta-annotations, we would have to allow them to be declared on annotations (i.e., @Target({ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) -- which is the easy part) and we would have to look them up using our merged annotation support instead of just looking them up as directly declared annotations (which is the more involved part... since the MethodParameter implementation would have modified considerably).

Comment From: bjerga

It would be great if @PathVariable could also be used as a meta-annotation. This would be handy when a path variable is used frequently in an application, similarly to what has been mentioned for the other annotations.

Comment From: sbrannen

Team Decision: we plan to support the following parameter annotations as meta-annotations in Spring Framework 6.0.

  • @CookieValue
  • @MatrixVariable
  • @ModelAttribute
  • @PathVariable
  • @RequestAttribute
  • @RequestBody
  • @RequestHeader
  • @RequestParam
  • @RequestPart
  • @SessionAttribute

Before releasing this feature, we should first assess whether there is any significant performance degradation due to the switch from simple synthesized annotations (supporting only @AliasFor semantics within a single annotation via SynthesizingMethodParameter) to fully merged annotations.

Comment From: sbrannen

Related Issues

  • 15386

  • 24981

  • 27621

  • 28950