You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make use of bean definition overriding more visible #31288
With errors that are hard to track, and with XML bean definitions taking always precedence over Java config (which can be surprising), we'd like to deprecate bean overriding wholesale with the idea of removing the feature at some point.
Spring Boot has already paved the way by disabling it by default and introducing a property to opt-in to the previous behavior. Us deprecating the feature in the core framework should send a strong signal to developers that they should not rely on that feature anymore.
Us deprecating the feature in the core framework should send a strong signal to developers that they should not rely on that feature anymore.
Could you please elaborate on how one might go about doing the same sort of thing when the particular bean is not marked as conditional? For example, what is the right strategy for overriding this bean?
Should we examine the conditions that trigger the creation of this bean and rework the app to disable those conditions? (In this case, rename the language bundle?)
Could we start sending pull requests that mark such beans with a @ConditionalOnMissingBean and family?
So we're going to change this particular issue to log a warning that indicates why it is being logged and that a next release will make it more noisy. We will also update the reference guide to indicate that users should move away from that feature and how. Once that's done we will advocate the Spring Boot property to be deprecated.
Deprecation of the feature proper is now scheduled for Spring Framework 7 to give enough room for users to notice and plan accordingly.
@mmoayyed If you want to override it in your configuration, it won't be possible and the mitigation will happen on a case by case basis. For tests, we are working to give users a first class support for overriding specific beans.
In the meantime support for bean overriding in tests has landed in 6.2.0-SNAPSHOT. The doc above provides an overview if you want to give the snapshots a try.
Giving this a try on our own projects revealed quite a number of issues. If we pursue with this, we should probably introduce a flag that we can use to opt-in for an exception as the warning alone makes it harder to validate that things are working as expected.
Activity
[-]Deprecate bean overidding[/-][+]Deprecate bean overriding[/+]dearoneesama commentedon Sep 21, 2023
It scares me off, but It looks like we are not talking about overriding @Bean-decorataed methods right?
snicoll commentedon Sep 22, 2023
registering twice a bean definition for the same key (i.e. bean name).
[-]Deprecate bean overriding[/-][+]Deprecate bean definition overriding[/+]mmoayyed commentedon Jan 23, 2024
Could you please elaborate on how one might go about doing the same sort of thing when the particular bean is not marked as conditional? For example, what is the right strategy for overriding this bean?
@ConditionalOnMissingBeanand family?snicoll commentedon Feb 12, 2024
So we're going to change this particular issue to log a warning that indicates why it is being logged and that a next release will make it more noisy. We will also update the reference guide to indicate that users should move away from that feature and how. Once that's done we will advocate the Spring Boot property to be deprecated.
Deprecation of the feature proper is now scheduled for Spring Framework 7 to give enough room for users to notice and plan accordingly.
@mmoayyed If you want to override it in your configuration, it won't be possible and the mitigation will happen on a case by case basis. For tests, we are working to give users a first class support for overriding specific beans.
[-]Deprecate bean definition overriding[/-][+]Log a warning when bean definition overriding is used[/+]snicoll commentedon Mar 11, 2024
We probably need to rephrase the note in https://docs.spring.io/spring-framework/reference/6.2-SNAPSHOT/testing/annotations/integration-spring/annotation-beanoverriding.html#spring-testing-annotation-beanoverriding-mockitobean.
In the meantime support for bean overriding in tests has landed in
6.2.0-SNAPSHOT. The doc above provides an overview if you want to give the snapshots a try.snicoll commentedon Mar 26, 2024
Giving this a try on our own projects revealed quite a number of issues. If we pursue with this, we should probably introduce a flag that we can use to opt-in for an exception as the warning alone makes it harder to validate that things are working as expected.
snicoll commentedon Mar 27, 2024
This is where we are with my testing https://ge.spring.io/s/rx7ixhsvowv4m
[-]Log a warning when bean definition overriding is used[/-][+]Make use of bean definition overriding more visible[/+]Make use of bean definition overriding more visible