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

Add Annotation for bean overriding [SPR-17519] #22051

Closed
spring-projects-issues opened this issue Nov 19, 2018 · 3 comments
Closed

Add Annotation for bean overriding [SPR-17519] #22051

spring-projects-issues opened this issue Nov 19, 2018 · 3 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

huehnerlady opened SPR-17519 and commented

We like the idea that with spring boot 2.1.0 the default value for the property spring.main.allow-bean-definition-overriding is now set to false.

But this comes with a challenge. We have tests which override one specific bean with a mock for integration testing. Now for these tests we get a BeanOverrideException.
We currently use the workaround with setting the property spring.main.allow-bean-definition-overriding to true for these specific tests, but in the end we might miss other overridden beans in a test which makes the app fail to start later. So we have to add another (expensive) Integration test that checks whether the app starts up without any errors.

So my proposal is to add an annotation - kind of similar to @Primary, that says that you actively want to override ONE SPECIFIC bean and make THIS bean primary.

Other idea is to just have an annotation to allow ONE SPECIFIC bean to be overridden and add the @Primary annotation as well.

What do you think?


Reference URL: spring-projects/spring-boot#15216 (comment)

@spring-projects-issues spring-projects-issues added status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement and removed type: enhancement A general enhancement labels Jan 11, 2019
@sbespalov
Copy link

we had the same issue after switching to Spring Boot v.2.1.0, the solution was to rename beans, that we have in test environment.
So the @Primary annotation still works with autowiring by type, if there is no bean name conflicts.

@dmurat
Copy link

dmurat commented Mar 29, 2019

Beside annotation, I think it will be useful to expand allow-bean-definition-overriding with an additional suffix, i.e. names, which will allow specifying a list of bean names which are allowed to be overridden.

@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 10, 2021
@snicoll
Copy link
Member

snicoll commented Sep 26, 2023

Unfortunately, we're leading towards deprecating bean definition overriding altogether, see #31288.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 26, 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) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

5 participants