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
-
20615
-
21108
-
31093
Deliverables
- [x] Revise
AnnotationBeanNameGenerator#determineBeanNameFromAnnotation()
to look up@Component
stereotype names using@AliasFor
semantics. - [x] Update documentation for
@Component
to inform users that custom stereotypes can make use of@AliasFor
to create an alias for@Component(value)
.
Comment From: sbrannen
Current work on this feature can be viewed in the following feature branch: https://github.com/spring-projects/spring-framework/compare/main...sbrannen:spring-framework:issues/gh-31089-Component-stereotype-names-and-AliasFor
Comment From: sbrannen
Reopening to update the Annotations page in the wiki.
Comment From: sbrannen
Updated the wiki page.