<bean id=」car」 class=」com.smart.attr.Car」> java
<property name=」speed」> spring
<value>2000</value> spa
</property> xml
</bean> 對象
也能夠將value做爲property屬性使用,當value值包涵xml標籤或其餘可能引發xml異常的符號時,應該使用<![CDATE[String]]>,把其中內容當字符串解析 字符串
<bean id=」person」 class=」com.smart.person」> it
<property name=」car」> io
<ref bean=」car」/> class
</property> 配置
</bean>
<bean id=」car」 class=」com.smart.attr.Car」/>
<ref >屬性有bean/local/parent
重要包括List、Set、Map、Properties
(1) List
<bean id=」person」 class=」com.smart.person」>
<list>
<value>讀書</value>
<value>看報</value>
<value>游泳</value>
</list>
</bean>
能夠直接注入字符串,也能夠經過<ref>注入其餘Bean;Set相似
(2) Map
<bean id=」person」 class=」com.smart.person」>
<property name=」name」>
<map>
<entry>
<key><value>key</value></key>
<value>value</value>
</entry>
</map>
</property>
</bean>
(3) Properties
Properties能夠看做Map的特例,Map的鍵值可使任何類型的對象,而Properties鍵值只能是字符串
<bean id=」person」 class=」com.smart.person」>
<property name=」name」>
<props>
<prop key=」key」>value</prop>
</props>
</property>
</bean>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd>
…..
<util:list id=」favorite」 list-class=」java.util.ArrayList」>
<value>value</value>
</util:list>
<util:set id=」」 set-class=」」>
<value></value>
</util:list>
<util:map id=」」 map-class=」」>
<entry key=」」 value=」」 />
</util:map>
<! --list 和set支持 value-type map支持key-type和value-type 限定值類型 -- >
……
<! –p命名空間簡化配置 -- >
<bean id=」car」 class=」」
p:brand=」」
p:maxSpeed=」」
p:price=」」 />
<bean id=」person」 class=」」
p:car-ref=」car」/>
</bean>