Add Annotation for bean overriding [SPR-17519] #22051
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
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-overridingis 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?
Reference URL: spring-projects/spring-boot#15216 (comment)
The text was updated successfully, but these errors were encountered: