This is a consequence of how Spring autowires constructors.
The first thing it does is gets all the bean class' constructors and sorts them, putting public constructors first with decreasing amount of arguments, then all non-public constructors again with decreasing amount of arguments. These are the candidate constructors.
It then iterates through these candidates, trying to generate the arguments from the BeanFactory
. If it can't because a bean is missing or for whatever other reason, it skips the candidate. If it succeeds in finding the arguments, it gives the current candidate constructor a weight based on a number of factors (argument list length, how close the types of the arguments vs the parameters are, etc.). It then checks the previous candidate's weight and swaps them if one is better than the other.
If there is a candidate constructor at the end of this process, Spring uses it.
If you're saying that Spring is using your 2 arg constructor over your 3 arg constructor, then that means you don't have a bean of one of the types in your 3 arg constructor.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…