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】Remove Linked List Elements(easy)

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  2. 【leetcode】Spiral Matrix II (middle)

    Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...

  3. Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]

    平时用的都是Centos系统,今天偶然在Ubuntu下编译了一次代码,发现报错了: 源码: #include <stdio.h> #include <sys/time.h> # ...

  4. Loadrunner连接Mysql数据库

    1.库文件下载地址:http://files.cnblogs.com/files/xiaoxitest/MySQL_LoadRunner_libraries.zip 分别添加到Loadrunner b ...

  5. AFNetworking请求设置请求头

    NSString *url = @"INPUT URL HERE"; AFHTTPRequestOperationManager *manager = [AFHTTPRequest ...

  6. python 取两数的百分比

    Python (r266:, Jan , ::) [GCC (Red Hat -)] on linux2 Type "help", "copyright", & ...

  7. Redis笔记(七)Java实现Redis消息队列

    这里我使用Redis的发布.订阅功能实现简单的消息队列,基本的命令有publish.subscribe等. 在Jedis中,有对应的java方法,但是只能发布字符串消息.为了传输对象,需要将对象进行序 ...

  8. 关于Java反射机制的几个问题

    >>如何在运行时确定对象类型 运行时类型识别(Run-time Type Identification, RTTI)主要有两种方式, 一种是在编译时和运行时已经知道了所有的类型,另外一种是 ...

  9. POJ 2299 Ultra-QuickSort 逆序数 树状数组 归并排序 线段树

    题目链接:http://poj.org/problem?id=2299 求逆序数的经典题,求逆序数可用树状数组,归并排序,线段树求解,本文给出树状数组,归并排序,线段树的解法. 归并排序: #incl ...

  10. css3 妙味

    css3 属性 <!DOCTYPE html> <html> <head lang="en"> <meta charset="U ...