You should separate the concepts of bean instantiation and autowiring.
If a class A
defined as a bean (for example by putting a @Component
on it) cannot be instantiated for some reason the application context won't start, period.
This is regardless the dependencies of the bean itself.
Now, if you have beans A
and beans B
and bean C
that has two "candidates" for auto-wiring , then it looks like this:
public interface I {}
@Component
public class A implements I {}
@Component
public class B implements I {}
@Component
public class C {
@Autowired
private I i;
}
In this case class C won't be instantiated and the whole Application Context will fail because spring won't know which implementation you'll have to use in class C (two candidates for autowiring).
In this case you need to give hints to Spring:
- by using
@Primary
annotation
- by using
@Qualifier
annotation
So to wrap-up the process of initialization of Application Context must be deterministic and well defined.