首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Spring读书笔记-Spring的Bean之设立Bean值

2013-03-19 
Spring读书笔记-----Spring的Bean之设置Bean值?xml version1.0 encodingUTF-8?beans xmlns:xsi

Spring读书笔记-----Spring的Bean之设置Bean值

<?xml version="1.0" encoding="UTF-8"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://www.springframework.org/schema/beans"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- 定义一个普通的Axe Bean --><bean id="steelAxe" class="com.spring.service.impl.SteelAxe" /><bean id="stoneAxe" class="com.spring.service.impl.StoneAxe" /><!--定义Chinese Bean --><bean id="chinese" class="com.spring.service.impl.Chinese"><property name="schools"><list><value>小学</value><value>中学</value><value>大学</value></list></property><property name="scores"><map><entry key="语文" value="88" /><entry key="数学" value="87" /><entry key="外语" value="88" /></map></property><property name="phaseAxes"><map><entry key="原始社会" value-ref="stoneAxe" /><entry key="农业社会" value-ref="steelAxe" /></map></property><property name="health"><props><prop key="血压">正常</prop><prop key="身高">175</prop></props></property><property name="axe"><set><value>普通字符串</value><bean class="com.spring.service.impl.SteelAxe"></bean><ref local="stoneAxe"/></set></property><property name="books"><list><value>java 编程思想</value><value>思考致富</value><value>将才</value></list></property></bean></beans>

          从上面的配置文件中可以看出,Spring对list属性和数组属性的处理是一样的。

当我们使用<list.../>、<set.../>、<map.../>等元素配置集合属性时,我们还需要手动配置集合元素。由于集合元素又可以是基本类型值、引用容器中的其他Bean、嵌套Bean和集合属性等。所以这些元素又可以接受如下子元素:

          value:指定集合元素是基本数据类型或者字符类型值。

          ref:指定集合元素师容器中另一个Bean实例。

          bean:指定集合元素是一个嵌套Bean。

          list、set、map、props:指定集合元素值又是集合。


读李刚《轻量级Java EE企业应用实战》

热点排行