FactoryBean的targetXXXClass屬性值指定集合類型,sourceXXX屬性指定集合元素的值。java
<bean id="sequenceGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="prefixGenerator" ref="datePrefixGenerator" /> <property name="initial" value="100000" /> <property name="suffixes"> <!-- 使用FactoryBean --> <bean class="org.springframework.beans.factory.config.SetFactoryBean"> <!-- 設置集合類型 --> <property name="targetSetClass"> <value>java.util.TreeSet</value> </property> <!-- 設置集合元素 --> <property name="sourceSet"> <set> <value>5</value> <value>10</value> <value>20</value> </set> </property> </bean> </property> </bean>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <bean id="sequenceGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="suffixes"> <!-- 設置集合類型 --> <util:set set-class="java.util.TreeSet"> <!-- 設置集合元素 --> <value>5</value> <value>10</value> <value>20</value> </util:set> </property> </bean> </beans>
<beans ...> <bean id="sequenceGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="suffixes"> <ref local="suffixes" /> </property> </bean> <bean id="suffixes" class="org.springframework.beans.factory.config.SetFactoryBean"> <!-- 設置集合類型 --> <property name="targetSetClass"> <value>java.util.TreeSet</value> </property> <!-- 設置集合元素 --> <property name="sourceSet"> <set> <value>5</value> <value>10</value> <value>20</value> </set> </property> </bean> </beans>
<beans ...> <bean id="sequenceGenerator" class="com.apress.springrecipes.sequence.SequenceGenerator"> <property name="suffixes"> <ref local="suffixes" /> </property> </bean> <util:set id="suffixes" set-class="java.util.TreeSet" > <value>5</value> <value>10</value> <value>20</value> </util:set> </beans>