Spring(3.2.3) - Beans(5): 集合属性的注入

如果 Bean 的属性是个集合,则可以使用 <list/>、<set/>、<map/> 和 <props/> 元素向 List、Set、Map 和 Properties 类型的属性注入值。

 

注入集合值的配置示例:

<bean id="moreComplexObject" class="example.ComplexObject">

    <!-- results in a setAdminEmails(java.util.Properties) call -->

    <property name="adminEmails">

        <props>

            <prop key="administrator">[email protected]</prop>

            <prop key="support">[email protected]</prop>

            <prop key="development">[email protected]</prop>

        </props>

    </property>

    <!-- results in a setSomeList(java.util.List) call -->

    <property name="someList">

        <list>

            <value>a list element followed by a reference</value>

            <ref bean="myDataSource" />

        </list>

    </property>

    <!-- results in a setSomeMap(java.util.Map) call -->

    <property name="someMap">

        <map>

            <entry key="an entry" value="just some string" />

            <entry key="a ref" value-ref="myDataSource" />

        </map>

    </property>

    <!-- results in a setSomeSet(java.util.Set) call -->

    <property name="someSet">

        <set>

            <value>just some string</value>

            <ref bean="myDataSource" />

        </set>

    </property>

</bean>

 

你可能感兴趣的:(spring)