Version: 5.2.1.RELEASE
Given the following configuration:
@Configuration
public class BaseTestConfig {
@Autowired
private Collection<String> strings;
@Bean
public String stringA() {
return "A";
}
@Bean
public String stringB() {
return "B";
}
@Bean
public DemoClass demoBean() {
System.out.println("Base config autowired strings: " + strings.size());
return new DemoClass(strings);
}
class DemoClass {
private final Collection<String> strings;
public DemoClass(Collection<String> strings) {
this.strings = strings;
}
public Collection<String> getStrings() {
return strings;
}
}
}
When demoBean is instantiated, it prints:
Base config autowired strings: 2
If we add another config file with content:
@Configuration
public class Extension1TestConfig {
@Bean
public String stringC() {
return "C";
}
}
when demoBean is instantiated, it prints:
Base config autowired strings: 1
We expect to have the 3 string beans injected into demoBean (2 beans of BaseTestConfig and 1 bean of Extension1TestConfig). However, as soon as another configuration file is declaring some String beans, the beans declared in BaseTestConfig are not injected anymore in the collection (strings) and only the beans of the other context(s) are injected.
Version: 5.2.1.RELEASE
Given the following configuration:
When
demoBeanis instantiated, it prints:If we add another config file with content:
when
demoBeanis instantiated, it prints:We expect to have the 3 string beans injected into
demoBean(2 beans ofBaseTestConfigand 1 bean ofExtension1TestConfig). However, as soon as another configuration file is declaring some String beans, the beans declared inBaseTestConfigare not injected anymore in the collection (strings) and only the beans of the other context(s) are injected.