Based on the configuration file, the following activities should happen:
S - calling to empty constructor.
P - we are calling to the contractors with two depended and MS string.
D2 - constructorr with one input 'MS'.
D1 - constructore with input 'MS'
The issue is that during the autowiring process Spring initializes the S constructor with the String argument which is not expected to be called.
Program Output: S Argument Constructor!
D1 Constructor with input: MS S Argument Constructor!
D2 Constructor with input: MS
P Constructor: D1: com.zohar.D1@4566e5bd, D2: com.zohar.D2@1ed4004b , Input: MS
S Empty Constructor!
This seems like a private case due to the second constructors that the depended class have (Seems like an issue with the reflection process).
The solution to this issue is to add the wrapper class as a type to the 'constructor-arg' tag:
Spring doesn't find constructor D1(String input) at first time, it loops all of constructors declared by D1, on my machine, the order is first D1(S s, String input), then D1(String input). When checking D1(S s, String input), S(String str) is involved because of constructor-arg MS, then Spring finally finds that D1(String input) satisfies constructor-arg MS instead of D1(S s, String input), the detail is in ConstructorResolver.java.
Your solution specifies type in constructor-arg, the code goes differently at here, when doesn't specify type in constructor-arg, valueHolder will not be null, while valueHolder will be null when specify type in constructor-arg.