Allow bean definitions from @Configuration classes to override those defined in XML [SPR-7341] #12000
Labels
has: votes-jira
Issues migrated from JIRA with more than 10 votes at the time of import
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
type: enhancement
A general enhancement
Eric Sirianni opened SPR-7341 and commented
The ConfigurationClassBeanDefinitionReader hardcodes the behavior that bean definitions from XML always override bean definitions from JavaConfig classes:
I don't see why this decision was made. The normal semantics of using the order in which bean definitions were registered would seem to make sense to apply here as well.
For example:
I would expect the following override order to apply:
Instead it appears the override order is:
This is not intuitive. Specifically, note the interleaving of beans between both Foo and Bar configurations. The clients who use FooConfig and BarConfig don't care whether the beans defined by those Configuration classes come from XML or java. Yet, the override ordering forces them to be aware of this implementation detail.
I realize changing the behavior outright might present a backwards compatibility issue, so is it possible to add a boolean option to the ApplicationContext to respect the registration ordering regardless of whether the bean definition comes from XML or JavaConfig?
Affects: 3.0.3
Issue Links:
@Bean
methods to override definitions in XML24 votes, 21 watchers
The text was updated successfully, but these errors were encountered: