Spring Framework allows to inject the dependency by setter method also. The
There are following values injected through setter injection.
• Primitive Values
• Dependent Object
• Collection values
Here I am taking example to inject Primitive values using Setter injection.
This file contains the
This file contains the code to obtain emp bean from applicationContext.xml.
Spring Framework provides following elements to inject collection values inside
Collection elements can be primitive or object collections.Here we’re taking example of Question class which has multiple answers.
Question class has collection of String for multiple answers.
This file contains bean entry for Question class.
This file contains the code to obtain the object of Question from applicationContext.xml.
Spring Framework allows to inject primitive or Object references with collection.There are three XML elements available for this.
• < list >
• < set >
• < map >
Syntax For Primitive values Collection
Here is syntax to define collection of primitive values.
Syntax For Object values Collection
Here is syntax to define collection of object values.
In this example, we are taking the example of Customer and Address where Customer one or more addresses.
For Dependent Object injection we have HAS-A relation scenario.In our case there is dependency of Address object in Customer class.
This file contains the bean entry for Customer bean.
This file has code to get the object of cust bean from applicationContext.xml.