Description
Overview
Although #20615 introduced the use of @AliasFor
for @Component(value)
in stereotype annotations (@Service
, @Controller
, @Repository
, @Configuration
, @RestController
), the framework does not actually rely on @AliasFor
support when looking up a component name via stereotype annotations. Rather, the framework has custom annotation parsing logic in AnnotationBeanNameGenerator#determineBeanNameFromAnnotation()
which effectively ignores explicit annotation attribute overrides configured via @AliasFor
.
Thus, although we can introduce the use of @AliasFor
in @ControllerAdvice
and @RestControllerAdvice
to create aliases for @Component(value)
(see #21108), those aliases will not be honored unless we revise the algorithm in AnnotationBeanNameGenerator
.
Related Issues
- Stereotype annotations like
@Service
should add@AliasFor
for@Component
[SPR-16066] #20615 - Allow component name to be specified in
@ControllerAdvice
[SPR-16566] #21108 - Deprecate convention-based
@Component
stereotype names in favor of@AliasFor
#31093
Deliverables
- Revise
AnnotationBeanNameGenerator#determineBeanNameFromAnnotation()
to look up@Component
stereotype names using@AliasFor
semantics. - Update documentation for
@Component
to inform users that custom stereotypes can make use of@AliasFor
to create an alias for@Component(value)
.