1 可使用<list> <map> <set>等来配置集合属性

2 List
  <!-- 配置List属性 -->
  <bean id="person3" class="com.kejian.spring.bean.collectionbean.PersonForList">
    <property name="name" value="Peter"></property>
    <property name="age" value="30"></property>
    <property name="cars">
    <list>
      <ref bean="car1"/>
      <ref bean="car2"/>
    </list>
    </property>
  </bean>

3 Map
  <!-- 配置Map属性 -->
  <bean id="person4" class="com.kejian.spring.bean.collectionbean.PersonForMap">
    <property name="name" value="Mike"></property>
    <property name="age" value="35"></property>
    <property name="cars">
      <map>
        <entry key="ACar" value-ref="car1"></entry>
        <entry key="BCar" value-ref="car2"></entry>
      </map>
    </property>
  </bean>

4 Props:配置properties
  <!-- 通过props来配置properties -->
  <bean id="datasource" class="com.kejian.spring.bean.collectionbean.Datasource">
    <property name="properties">
      <props>
        <prop key="user">root</prop>
        <prop key="password">root</prop>
        <prop key="url">jdbc:mysql.///test</prop>
        <prop key="driver">jdbc.mysql.driver</prop>
      </props>
    </property>
  </bean>

5 单独配置集合bean:需引入Util shema
  <!-- 单独配置集合 -->
  <util:list id="cars">
    <ref bean="car1"/>
    <ref bean="car2"/>
  </util:list>

6 使用p shema更快捷配置bean属性:需引入p shema
  <!-- 通过p命名空间来配置bean属性 -->
  <bean id="person5" class="com.kejian.spring.bean.collectionbean.PersonForList"
    p:name="Jack" p:age="22" p:cars-ref="cars">

  </bean>

Spring -配置集合属性的更多相关文章

  1. Spring基础07——配置集合属性

    1.集合属性 在Spring中可以通过一组内置的xml标签(例如<list>,<set>或<map>)来配置集合属性. 2.配置List集合 配置java.util ...

  2. Spring学习--集合属性

    Spring 中可以通过一组内置的 xml 标签(例如: <list> , <set> 或 <map>) 来配置集合属性. 配置java.util.Set 需要使用 ...

  3. [原创]java WEB学习笔记98:Spring学习---Spring Bean配置及相关细节:如何在配置bean,Spring容器(BeanFactory,ApplicationContext),如何获取bean,属性赋值(属性注入,构造器注入),配置bean细节(字面值,包含特殊字符,引用bean,null值,集合属性list map propert),util 和p 命名空间

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  4. spring 配置属性的详细信息

    摘要(这篇文章讲的红,蓝说这话节) 字面值 字面值:可用字符串表示的值,能够通过<value>元素标签或value属性进行注入 基本数据类型及其封装类.String等类型都能够採取字面值注 ...

  5. Spring(八):Spring配置Bean(一)BeanFactory&ApplicationContext概述、依赖注入的方式、注入属性值细节

    在Spring的IOC容器里配置Bean 配置Bean形式:基于xml文件方式.基于注解的方式 在xml文件中通过bean节点配置bean: <?xml version="1.0&qu ...

  6. Spring容器的属性配置详解的六个专题

    在spring IOC容器的配置文件applicationContext.xml里,有一些配置细节值得一提.我们将一些问题归结为以下几个专题.   专题一:字面值问题 配置的bean节点中的值,我们提 ...

  7. spring 配置属性细节

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/qilixiang012/article/details/28233811 概要(红色为上一篇所讲,蓝 ...

  8. spring 配置bean

    Main(测试方法) public class Main { public static void main(String[] args) { //1.创建Spring 的IOC容器对象: //spr ...

  9. Spring4学习笔记2-配置集合属性

    1 可使用<list> <map> <set>等来配置集合属性 2 List <!-- 配置List属性 --> <bean id="p ...

随机推荐

  1. 【leetcode】Next Permutation(middle)

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  2. IOS - 屏幕适配

    原文:Beginning Auto Layout Tutorial in iOS 7: Part 1 感谢翻译小组成员@answer-huang(博客)热心翻译.如果您有不错的原创或译文,欢迎提交给我 ...

  3. 当对服务器端返回的极光推送数据请求时,AFN 的 GET 请求失败如何解决

    代码段 控制台   只需在 manager 那里添加一行代码即可 //传入json格式数据,不写则普通post     manager.requestSerializer = [AFJSONReque ...

  4. CSS命名法

    一.Css命名法: 1.驼峰命名法:除第一个单词的首字母小写之外,其余的单词首字母均大写.如:#headBlock(2). 2.帕斯卡命名法:所有单词的首字母均大写.如:#HeadBlock(3). ...

  5. 【转】VS项目属性的一些配置项的总结

    首先,解决方案和项目文件夹包含关系(c++项目): VS解决方案和各个项目文件夹以及解决方案和各个项目对应的配置文件包含关系,假设新建一个项目ssyy,解决方案起名fangan,注意解决方案包括项目, ...

  6. windows重新获取IP

    win+r------->cmd------>ipconfig /release (释放ip) ipconfig /renew  重新获取ip

  7. Jquery学习笔记---闭包

    1. 简要介绍 闭包可谓是js中的一大特色了,即使你对闭包没概念,你可能已经在不知不觉中使用到了闭包.闭包是什么,闭包就是一个函数可以访问到另一个函数的变量.这就是闭包,解释起来就这么一句话,不明白? ...

  8. [LeetCode] Largest Rectangle in Histogram

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  9. 攻城狮在路上(叁)Linux(三十一)--- vim程序编辑器

    本篇主要介绍vim编辑器的使用方式,具体内容后续补充.

  10. 攻城狮在路上(叁)Linux(二十六)--- linux文件系统的特殊查看与操作

    一.boot sector 与 super block的关系: 1.boot sector用于存放引导装载程序,占用1024个字节. 2.super block的大小也为1024字节. 3.若bloc ...