Spring DI- Constructor Injection with XML Metadata configuration

In Constructor injection spring container invokes a constructor or a static factroy method  with the number of argument. Where each arguments represents a dependency. Argument to static factory method or constructor are similar.
If no potential ambiguity exists in the constructor arguments of a bean definition, then the order in which the constructor arguments are defined in a bean definition is the order in which those arguments are supplied to the appropriate
constructor when the bean is being instantiated.

Constructor / Factory method argument resolution: There could be ambiguity in argument list to constructor or factory method.
Example: Address class has properties as

     flatNo(String type) ,
     bldgNo(String type),
     streetNo(String type),
     city (int type),
     pincode (int type)

Constructor for contact class has the properties in order of(flatNo, bldgNo, streetNo, city, pincode) OR (String, String, String, String, int)

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.