Dave Syer opened SPR-7028 and commented
There are two ways I might want to do this, and both fail.
- Use
@ImportResource in an @Configuration to load an XML file, then override a bean using @Bean
- Write an XML file that imports another file and then defines a bean that is
@Configuration, and the latter provides a bean with the same name
Neither works.
Case 1 fails because ConfigurationClassBeanDefinitionReader always loads XML imports after the @Bean definitions. This seems like the wrong order, so it would be good to understand why it is implemented that way (I imported before I defined the @Bean, so I expect the latter to win).
This code in ConfigurationClassBeanDefinitionReader prevents the override in case 2:
if (!(existingBeanDef instanceof ConfigurationClassBeanDefinition)) {
// no -> then it's an external override, probably XML
// overriding is legal, return immediately
return;
}
Affects: 3.0.1
Issue Links:
8 votes, 12 watchers
Dave Syer opened SPR-7028 and commented
There are two ways I might want to do this, and both fail.
@ImportResourcein an@Configurationto load an XML file, then override a bean using@Bean@Configuration, and the latter provides a bean with the same nameNeither works.
Case 1 fails because
ConfigurationClassBeanDefinitionReaderalways loads XML imports after the@Beandefinitions. This seems like the wrong order, so it would be good to understand why it is implemented that way (I imported before I defined the@Bean, so I expect the latter to win).This code in
ConfigurationClassBeanDefinitionReaderprevents the override in case 2:Affects: 3.0.1
Issue Links:
@Configurationclasses to override those defined in XML8 votes, 12 watchers