Beside injecting a simple value (using the
value attribute) and a reference to other bean (using the
ref attribute). We can also inject collections properties into a bean.
Spring provides four ways to inject collections. There are
<set> that can be used to inject arrays or any implementation of
<map> that can be used to inject property of type
java.util.Map. And the
<props> can be used to inject property of type
Here is a table that summarize the collection configuration support in Spring.
||Wiring a list of values, where the values might have duplicates.|
||Wiring a set of values, where the values can not have duplicates.|
||Wiring a key-value pairs collection, where the key and value can be any type|
||Wiring a key-value pairs property, where the key and value are both type of String|
You can see the following example on how to use each type of this collection configuration: