I would like to ask about the Spring Constructor Injection. So in the class, I have two constructors with different number of arguments.
public class MyClassHello() {
public MyClassHello(String A) {
// do sth
}
public MyClassHello(String A, int B){
// do sth
}
}
If I try to inject like this to access the 1st constructor, Spring can not work since there is ambiguity.
<bean id="injectQuestion" class="MyClassHello">
<constructor-arg index="0" value="A String"/>
</bean>
The debug code is like this:
Unsatisfied dependency expressed through constructor argument with index 1 of type [java.lang.String]: Ambiguous constructor argument types.
I think it means, Spring needs to know if the index 1 argument exists?
It is not like the usual case where we have two constructors with same number of arguments. Like that, I could set the type in order to distinguish when injecting.
In my case, is there anyway to force Spring to choose the first constructor?
Thanks a lot!!