如果一个集合对象不光光是注入到一个对象中,那我们需要考虑此集合对象设置ID
List
<bean id="mails" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<value>data1</value>
<value>data2</value>
<property>
</bean>Map
<bean id="mails" class="org.springframework.beans.factory.config.MapFactoryBean">
<property name="sourceMap">
<map>
<entry key="data1" value="data1"/>
<entry key="data2" value="data2"/>
</map>
<property>
</bean>Set
<bean id="mails" class="org.springframework.beans.factory.config.SetFactoryBean">
<property name="sourceSet">
<set>
<value>data1</value>
<value>data2</value>
</set>
<property>
</bean>
properties
<bean id="mails" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<props>
<prop key="somekey">somekey</prop>
<prop key="anykey">anykey</prop>
</props>
</bean>
<!---或者使用location属性->
<property name="localtion">
<value>src/config/config.properties</value>
</property>
本文详细介绍了如何在Spring框架中进行集合类型的注入,包括List、Map、Set及Properties等不同类型的数据结构配置方法。通过具体的XML配置示例展示了每种集合类型的具体注入方式。
2231

被折叠的 条评论
为什么被折叠?



