Spring

Spring - Injecting Collection

Spring - Injecting Collection

We have understood how to arrange primitive data types utilizing esteem property and object references utilizing the ref quality of the <property> tag in your Bean configuration record. Both the cases manage passing solitary worth to a bean. Presently consider the possibility of passing plural qualities like Java Collection types like List, Set, Map, and Properties. To deal with the circumstance, Spring offers four kinds of assortment setup components which are as per the following – 

Element with Explanation

<list> 

This aids in wiring, ie, infusing a rundown of qualities, permitting copies. 

<set> 

This aids in wiring a bunch of qualities yet with no copies. 

<map> 

This can be utilized to infuse an assortment of name-esteem sets where name and worth can be of any sort. 

<props> 

This can be utilized to infuse an assortment of name-esteem sets where the name and worth are the two Strings. 

You can utilize either <list> or <set> to wire any execution of java.util.Collection or an exhibit. You will run over two circumstances (a) Passing immediate upsides of the assortment and (b) Passing a bean reference as one of the assortment components.