I have an interface like this
public interface InterfaceA {
public String methodA();
}
and I have implemented it like this
public class ClassA implements InterfaceA {
@Override
public String methodA(){
return "HELLO";
}
}
I'm trying to reference a bean of this class in another class
public class ClassB {
@Autowired
private InterfaceA mybean;
String str = mybean.methodA();
}
I have the following bean configuration
<bean id="mybean" class="ClassA"></bean>
Most interesting point is if I remove all the declaration and implementation of the methodA
in InterfaceA
and ClassA
and then try to just this
public class ClassB {
@Autowired
private InterfaceA mybean;
}
no error is shown. In the other case the following error is shown when I try to run this application: "No qualifying bean of type [ClassA] found for dependency"