- <?xml version="1.0" encoding="UTF-8" ?>
- <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
- xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:util="http://www.springframework.org/schema/util" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
- http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
- http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
- <!-- 使用Spring表达式读取其它bean的属性值。 -->
- <bean id="sb1" class="value.SpelBean">
- <property name="name" value="#{vb1.name}" />
- <property name="interest" value="#{vb1.interest[0]}" />
- <property name="score" value="#{vb1.score['英语']}" />
- <property name="pageSize" value="#{config.pagesize}" />
- </bean>
- <bean id="vb1" class="value.ValueBean">
- <property name="name" value="小月" />
- <property name="age" value="22" />
- <property name="interest">
- <list>
- <value>
- 钓鱼
- </value>
- <value>
- 旅游
- </value>
- <value>
- 看电视
- </value>
- <value>
- 看电视
- </value>
- </list>
- </property>
- <property name="city">
- <set>
- <value>
- 北京
- </value>
- <value>
- 长沙
- </value>
- <value>
- 南京
- </value>
- </set>
- </property>
- <property name="score">
- <map>
- <entry key="英语" value="60" />
- <entry key="math" value="80" />
- </map>
- </property>
- <property name="db">
- <props>
- <prop key="username">
- King
- </prop>
- <prop key="password">
- 1234
- </prop>
- </props>
- </property>
- </bean>
- <!-- 引用的方式注入集合类型的值 -->
- <util:list id="interestBean">
- <value>
- 钓鱼
- </value>
- <value>
- 旅游
- </value>
- <value>
- 上网
- </value>
- </util:list>
- <util:set id="cityBean">
- <value>
- 北京
- </value>
- <value>
- 上海
- </value>
- <value>
- 武汉
- </value>
- </util:set>
- <util:map id="scoreBean">
- <entry key="english" value="80" />
- <entry key="math" value="90" />
- </util:map>
- <util:properties id="dbBean">
- <prop key="username">
- King
- </prop>
- <prop key="password">
- 1234
- </prop>
- </util:properties>
- <bean id="vb2" class="value.ValueBean">
- <property name="interest" ref="interestBean" />
- <property name="city" ref="cityBean" />
- <property name="score" ref="scoreBean" />
- <property name="db" ref="dbBean" />
- </bean>
- <!-- 读取properties文件的内容 -->
- <!-- location属性:指定要 读取的文件的位置, 其中,classpath:表示依据类路径去查找。 -->
- <util:properties id="config" location="classpath:config.properties" />
- </beans>
来源: http://www.bubuko.com/infodetail-1965392.html