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. 【linux】ubuntu stmp服务器配置

    来源:http://blog.itpub.net/786540/viewspace-1002077/ sudo apt-get install sendmail(其中已经包含了sendmail-bin ...

  2. (2016弱校联盟十一专场10.2) E.Coins

    题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...

  3. Log4j的使用

    一,Log4j简介 日志的三个目的: 1. 监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作                      2.跟踪代码运行时轨迹,作为日后审计的依 ...

  4. IOS - 屏幕适配

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

  5. Hibernate查询语句

    1 hql查询 Hibernate的查询语句,hiberante提供的面向对象的查询语言,和sql语句的语法的相似.而且严格区分大小写. 1.1 from字句 /** * hql: from 字句 * ...

  6. 实现iOS前台时的推送弹窗效果

    原文链接 或许很多童鞋还不知道,在 iOS 中收到推送通知时,如果 App 处于前台运行的情况下,推送的顶部弹窗是不会弹出来的. 然而就是有很多**的产品经理都会提出类似这样的**需求:那就是在 Ap ...

  7. core

    http://blog.csdn.net/xiaoxiaoniaoer1/article/details/7740820 1.core文件的生成开关和大小限制--------------------- ...

  8. Apache commons-dbutils笔记

  9. 通过mysql命令行理解mysql

    引言:工具不可谓给我们的生活带来了便利,但有些时候我们却忘记了事物本身的意义.在大多数人都在追捧甚至是盲从各种各样的工具有多先进的时候,你是否有反思过:你目前是否有使用它的资格. 假设你学会了使用一款 ...

  10. C#回顾 - 2.NET的IO:Path、File、FileInfo、Directory、DirectoryInfo、DriveInfo、FileSystemWatcher

        1.管理文件系统 一般而言,应用程序都会有保存数据.检索数据的需求. 1.1 使用 path 类来访问文件路径 [path常用的方法]:http://www.cnblogs.com/tangg ...