-
Notifications
You must be signed in to change notification settings - Fork 41.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add Annotation for bean overriding #15216
Comments
It's an interesting suggestion. Thank you. I'd prefer to avoid adding to the programming model if we can, though. There are a few existing ways, of varying degrees of elegance, to achieve what you want:
Do any of the above meet your needs? |
@wilkinsona this sounds very interesting, I tried the In this issue it sounds like you will not provide native support for Spock and the library mentioned in there does ed up in the same problem with the BeanDefinitionOverrideException. Will there be a change of mind and maybe support spock after all then? |
Sorry, but I don't think this issue will cause us to change our minds about supporting Spock with |
So you will not think about adding such an annotation to the spring boot framework then? Something like |
@huehnerlady That would be something that the Spring Framework team would need decided. You can raise a JIRA here for them to consider it if you like. I'd personally not be in favor of adding an additional annotation. |
For other people who might be interested: https://jira.spring.io/browse/SPR-17519 |
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
totrue
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?
The text was updated successfully, but these errors were encountered: