Suppose I have the following interface:
public interface Interface1 {
}
and the following class:
public class Class1 implements Interface1 {}
Also, I have this class:
public class Class2 {
private Interface1 interface;
public void setInterface(Interface1 interface) {
this.interface = interface;
}
}
What should I put in my applicationContext.xml to inject a bean generated by Class1 into Class2.interface? Also, is it possible to do it with annotations?
You just inject it like any other bean, as long as the Runtime types are compatible it will work fine, there’s no need to do anything special with the interface type in your XML.
@Autowiredwill also work fine, of course if there is more than one implementation of interface1 in the container, you will want to specify a bean name with@Qualifier.