Skip to content
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

Look up @Component stereotype names using @AliasFor semantics #31089

Closed
2 tasks done
sbrannen opened this issue Aug 22, 2023 · 3 comments
Closed
2 tasks done

Look up @Component stereotype names using @AliasFor semantics #31089

sbrannen opened this issue Aug 22, 2023 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Aug 22, 2023

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

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).
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Aug 22, 2023
@sbrannen sbrannen added this to the 6.1.0-RC1 milestone Aug 22, 2023
@sbrannen sbrannen self-assigned this Aug 22, 2023
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Aug 22, 2023
@sbrannen
Copy link
Member Author

Current work on this feature can be viewed in the following feature branch: main...sbrannen:spring-framework:issues/gh-31089-Component-stereotype-names-and-AliasFor

sbrannen added a commit that referenced this issue Aug 27, 2023
This commit builds on the recently added support for using @AliasFor to
override the `value` attribute in `@Component, and allows a custom
component name to be specified in both @ControllerAdvice and
@RestControllerAdvice via new `name` attributes.

See gh-31089
Closes gh-21108
sbrannen added a commit that referenced this issue Aug 28, 2023
…liasFor

When use of the deprecated feature is detected, a WARNING log message
will be generated analogous to the following.

WARN o.s.c.a.AnnotationBeanNameGenerator - Support for convention-based
stereotype names is deprecated and will be removed in a future version
of the framework. Please annotate the 'value' attribute in
@org.springframework.context.annotation.AnnotationBeanNameGeneratorTests$ConventionBasedComponent1
with @AliasFor(annotation=Component.class) to declare an explicit alias
for @component's 'value' attribute.

See gh-31089
Closes gh-31093
@sbrannen
Copy link
Member Author

Reopening to update the Annotations page in the wiki.

@sbrannen sbrannen reopened this Aug 29, 2023
@sbrannen
Copy link
Member Author

Updated the wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant