I have text editor class with below constructors
public class TextEditor {
private SpellChecker spellChecker;
private SpellChecker1 spellChecker1;
private SpellChecker2 spellChecker2;
public TextEditor(SpellChecker spellChecker) {
this.spellChecker = spellChecker;
}
public TextEditor(SpellChecker2 spellChecker2) {
this.spellChecker2 = spellChecker2;
}
public TextEditor(SpellChecker spellChecker, SpellChecker1 spellChecker1,SpellChecker2 spellChecker2) {
this.spellChecker = spellChecker;
this.spellChecker1 = spellChecker1;
this.spellChecker2 = spellChecker2;
}
public TextEditor(SpellChecker spellChecker, SpellChecker1 spellChecker1) {
this.spellChecker = spellChecker;
this.spellChecker1 = spellChecker1;
}
}
In spring-beans i have
<bean id="textEditor" class="com.TextEditor" autowire="constructor">
</bean>
what i observe is constructor with two arguments is called consistently. Is it random? Should not spring throw exception becoz it does not know which constructor needs to be called?
See Question&Answers more detail:os