Closed
Description
Benoit Lacelle opened SPR-10992 and commented
While overrding a Javaconfig Bean by extending the original @Configuration
class, I would like to add a @DependsOn
for the new Bean definition.
However, this depends-on seems not to be taken in account. here is a TestCase reproducing my issues:
public class SpringTest {
@Test
public void testDependsOnTakenInAccount() {
AnnotationConfigApplicationContext ctx2 = new AnnotationConfigApplicationContext(AConfig.class, CConfig.class);
Assert.assertEquals("overriden", ctx2.getBean("bean"));
}
@Configuration
public static class AConfig {
@Bean
public Object bean() {
return "not overriden";
}
}
@Configuration
public static class CConfig extends AConfig {
protected boolean isInitialized = false;
@Bean
public Void doInit() {
isInitialized = true;
return null;
}
@Bean
@DependsOn("doInit")
public Object bean() {
if (!isInitialized) {
throw new RuntimeException("Not initialized");
}
return "overriden";
}
}
}
Is this an expected behavior? If yes, how can I add dependency while overriding a bean?
Affects: 3.2.3
Issue Links:
- Cannot override singleton with scoped proxy [SPR-10744] #15370 Cannot override singleton with scoped proxy
- ConfigurationClass.validate() should allow for overloading in general or not at all [SPR-11025] #15653 ConfigurationClass.validate() should allow for overloading in general or not at all
0 votes, 5 watchers