Dependency Injection is the main functionality provided by Spring IOC(Inversion of Control). The Spring-Core module is responsible for injecting dependencies through either Constructor or Setter methods.
In Setter Dependency Injection(SDI) the dependency will be injected with the help of setters and getters methods. A bean-configuration file is used to set DI as SDI in the bean. For this, the property to be set with the SDI is declared under the <property> tag in the bean-config file.
Setter Injection with Dependent Object
If there exists a relationship between the classes of our spring application, then we create the instance of the dependent object also called the contained object. After creating the instance of the dependent object we pass it as an argument of the main class container. Example: If an employee has an address, then the instance of the Address class is the dependent object and will be contained in the Employee class.
Implementation: The following example demonstrates a setter injection with a dependent object.
Please Login to comment...