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

@Bean method should be always allowed to override scanned class matching its return type #31052

Closed
jhoeller opened this issue Aug 15, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@jhoeller
Copy link
Contributor

Following up on #25952, we should accept an @Bean method overriding a scanned component class even when general bean definition overriding has been disabled, as long as the bean class is the same. E.g. if a CustomController class with an @RestController stereotype has been found through classpath scanning, a configuration class with an @Bean CustomController customController() method should be allowed to replace it in order to configure it in a custom way. As long as the declared return type matches the bean class, the intent is clear and there is no real risk for an accidental override.

As a consequence, this allows for declaring stereotype annotations on a class returned from an @Bean method without running into conflicts with classpath scanning. This is preferable over declaring stereotype annotations on the @Bean method itself (which is not possible due to the limited declaration of our stereotype annotations anyway) since stereotypes are meant to apply to the component class, not to the factory method or the specific instance that it creates.

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Aug 15, 2023
@jhoeller jhoeller added this to the 6.1.0-M4 milestone Aug 15, 2023
@jhoeller jhoeller self-assigned this Aug 15, 2023
@jhoeller jhoeller changed the title @Bean method should be allowed to always override scanned class matching its return type @Bean method should be always allowed to override scanned class matching its return type Aug 15, 2023
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