With the @Qualifier
annotation it's possible to inject beans by name, so something like this is possible:
@Configuration
public class ClassCConfig {
@Bean(name = "c1")
public C createrC1() {
returns new C();
}
@Bean(name = "c2")
public C createrC2() {
...
}
@Bean(name = "c3")
public C createrC3() {
...
}
....
And then inject hose in different instances of A:
@Configuration
public class ClassAConfig {
@Autowired
@Qualifier("c1")
private C c1;
@Autowired
@Qualifier("c2")
private C c2;
...
@Bean(name = "a1")
public A createA1() {
...
}
@Bean(name = "a2")
public A createA2() {
...
}
With this it's possible to wire any tree of beans using only Java (scanned) configuration.