Java Reference
In-Depth Information
</entry>
</map>
</property>
</bean>
In all the collection classes seen thus far, you used values to set the properties. Sometimes the
desired goal is to configure a
null
value using a
Map
instance. Spring's XML configuration schema
includes explicit support for this. Here is a map with null values for the value of an entry:
<property name="nulledMapValue">
<map>
<entry>
<key>
<value>null</value>
</key>
</entry>
</map>
</property>
A
java.util.Properties
collection is very similar to a map. It also implements the
java.util.Map
interface and stores entries in key/value pairs. The only difference is that the keys and values of a
Properties
collection are always strings.
package com.apress.springenterpriserecipes.sequence;
...
public class SequenceGenerator {
...
private
Properties suffixes;
public void setSuffixes(
Properties suffixes) {
this.suffixes = suffixes;
}
...
}
To define a
java.util.Properties
collection in Spring, use the
<props>
tag with multiple
<prop>
tags
as children. Each
<prop>
tag must have a
key
attribute defined and the corresponding value enclosed.
<bean id="sequenceGenerator"
class="com.apress.springenterpriserecipes.sequence.SequenceGenerator">
...
<property name="suffixes">
<props>
<prop key="type">A</prop>
<prop key="url">
http://www.apress.com/</prop>
<prop key="null">null</prop>
</props>
</property>
</bean>
If you define your beans with inheritance, a child bean's collection can be merged with that of its
parent by setting the
merge
attribute to
true
. For a
<list>
collection, the child elements will be added.
Search WWH ::
Custom Search