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

Open
spring-projects-issues opened this issue Nov 19, 2018 · 2 comments
Open

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

spring-projects-issues opened this issue Nov 19, 2018 · 2 comments
Labels
in: core status: waiting-for-triage

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 19, 2018

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 type: enhancement and removed type: enhancement labels Jan 11, 2019
@sbespalov
Copy link

@sbespalov sbespalov commented Feb 14, 2019

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 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 label Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core status: waiting-for-triage
Projects
None yet
Development

No branches or pull requests

4 participants