Spring中注入List Set Map Properties的配置文件
Posted Bwz_Learning
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring中注入List Set Map Properties的配置文件相关的知识,希望对你有一定的参考价值。
对于Spring中注入List Set Map Properties的配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
<!-- bean -->
<bean id="person" class="spring.list.Person">
<property name="name" value="top" />
<property name="address" value="beijing"></property>
<property name="age" value="1"></property>
</bean>
<bean id="customerBean" class="spring.list.Customer">
<!-- list example -->
<property name="lists">
<list>
<value>3</value>
<ref bean="person" />
<bean name="otherBean" class="spring.list.Person">
<property name="name" value="myList" />
<property name="address" value="myaddress" />
<property name="age" value="24" />
</bean>
</list>
</property>
<!-- set example -->
<property name="sets">
<set>
<value>3</value>
<ref bean="person" />
<bean name="otherBean" class="spring.list.Person">
<property name="name" value="myList" />
<property name="address" value="myaddress" />
<property name="age" value="24" />
</bean>
</set>
</property>
<!-- map example -->
<property name="maps">
<map>
<entry key="example1" value="love1" />
<entry key="example2" value-ref="person" />
<entry key="example3">
<bean name="otherBean" class="spring.list.Person">
<property name="name" value="myList" />
<property name="address" value="myaddress" />
<property name="age" value="24" />
</bean>
</entry>
</map>
</property>
<!--properties -->
<property name="pros">
<props>
<prop key="key1">properties--value1</prop>
<prop key="key2">properties--value2</prop>
</props>
</property>
</bean>
</beans>
以上是关于Spring中注入List Set Map Properties的配置文件的主要内容,如果未能解决你的问题,请参考以下文章
spring List,Set,Map,Properties,array的配置文件注入方式
Spring集合 (List,Set,Map,Properties) 实例
Spring集合 (List,Set,Map,Properties) 实例
Spring3实战第二章第二小节 IOC依赖注入 list和map集合