Alexander Glass opened SPR-9567 and commented
Use case: I have my container configured via classpath scanning @ComponentScan. For my test configuration I need the ability to mock specific beans.
Due to the order of loading, beans loaded via classpath scan are not overriding properly when using @Configuration. The following code samples demonstrate the problem. BaseExample.java shows how it is possible to override beans via configuration. ScanExample.java shows that overriding a bean that was loaded via @ComponentScan is skipped.
From the logs:
21:21 DEBUG | o.s.c.a.ConfigurationClassBeanDefinitionReader | Skipping loading bean definition for [BeanMethod:name=accountDao,declaringClass=com.glassworks.demo.ScanExample$OverrideConfig]: a definition for bean 'accountDao' already exists. This is likely due to an override in XML.
The attached zipfile contains a maven project with sample code to illustrate.
Affects: 3.1.1
Reference URL: http://forum.springsource.org/showthread.php?128123-Overriding-Bean-Configuration-with-annotations
Attachments:
Issue Links:
9 votes, 17 watchers
Alexander Glass opened SPR-9567 and commented
Use case: I have my container configured via classpath scanning
@ComponentScan. For my test configuration I need the ability to mock specific beans.Due to the order of loading, beans loaded via classpath scan are not overriding properly when using
@Configuration. The following code samples demonstrate the problem. BaseExample.java shows how it is possible to override beans via configuration. ScanExample.java shows that overriding a bean that was loaded via@ComponentScanis skipped.From the logs:
21:21 DEBUG | o.s.c.a.ConfigurationClassBeanDefinitionReader | Skipping loading bean definition for [BeanMethod:name=accountDao,declaringClass=com.glassworks.demo.ScanExample$OverrideConfig]: a definition for bean 'accountDao' already exists. This is likely due to an override in XML.
The attached zipfile contains a maven project with sample code to illustrate.
Affects: 3.1.1
Reference URL: http://forum.springsource.org/showthread.php?128123-Overriding-Bean-Configuration-with-annotations
Attachments:
Issue Links:
@Primaryto override@ComponentScan-edbeans@Configurationoverride@Configurationimported via@ImportResourceis not processed9 votes, 17 watchers