在spring的配置文件中util命名空间类似于java.util包类对应,util命名空间提供了集合相关的配置,在使用命名空间前要导入util命名空间,如下:

  • util命名空间引入
 <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd">
  • spring中配置一个List
1     <!-- 使用util命名空间配置一个List集合 -->
2 <util:list id="userList" value-type="java.lang.String">
<value>张三</value>
<value>李四</value>
<value>王五</value>
</util:list>
  • spring中配置一个Map集合
 <!-- 配置一个Map集合 -->
<util:map id="userMap">
<entry key="user1" value-ref="user" />
<entry key="user2">
<!-- 配置一个内部Bean -->
<bean class="io.shuqi.ssh.spring.util.User">
<property name="userAge" value="12" />
<property name="userName" value="小张" />
</bean>
</entry>
</util:map>
  • spring中配置一个Set集合
 <!-- util配置一个Set集合 -->
<util:set id="userSet">
<value>张三</value>
<value>王五</value>
<value>赵六</value>
</util:set>
  • spring中配置一个Properties集合
<!--配置一个 Properties-->
<util:properties id="userProperties">
<prop key="name">张三</prop>
<prop key="age">12</prop>
</util:properties> <!-- 通过一个properties文件来配置一个properties-->
<util:properties location="classpath:io/shuqi/ssh/spring/util/jdbc.properties" id="jdbc" />

实际上<util:list>、<util:map>、<util:set>、<util:properties>等标签是spring用来取代ListFactoryBean、MapFactoryBean、SetFactoryBean、PropertiesFactoryBean的简单写法

  • spring中其他加载配置文件Properties的方式
     <!--
context:property-placeholder (PropertySourcesPlaceholderConfigurer)
加载一个 properties配置文件,并且可以在其他地方使用${key}表达式来占位属性值,
*spring 2.5以前可以注册bean(org.springframework.context.support.PropertySourcesPlaceholderConfigurer)来加载配置文件
-->
<!-- spring 2.5 以前使用注册bean的方式来加载配置文件 -->
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer" p:location="classpath:io/shuqi/ssh/spring/util/jdbc.properties"></bean>
<!-- 使用context命名空间的方式加载Properties文件 -->
<context:property-placeholder location="classpath:io/shuqi/ssh/spring/util/jdbc.properties" />

spring util命名空间的更多相关文章

  1. 曹工说Spring Boot源码(8)-- Spring解析xml文件,到底从中得到了什么(util命名空间)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  2. spring-第十篇之XML Schema的简化配置,p、c、util命名空间

    1.p:命名空间 引入命名空间:xmlns:p="http://www.springframework.org/schema/p" 配置举例: <?xml version=& ...

  3. 什么是Spring的命名空间及使用Spring 的命名空间p 装配属性

    这个就要从XML说了,Spring的配置管理可以利用XML方式进行配置,而XML里面就有命名空间这个概念..实际上就和标签的意思有点像 你给一个命名空间以后,这个XML文件里面就可以用那个命名空间上下 ...

  4. 使用Spring的命名空间p装配属性-摘自《Spring实战(第3版)》

    使用<property>元素为Bean的属性装配值和引用并不太复杂.尽管如此,Spring的命名空间p提供了另一种Bean属性的装配方式,该方式不需要配置如此多的尖括号. 命名空间p的sc ...

  5. Spring P命名空间 02

    P命名空间 装配属性 使用<property> 元素为Bean 的属性装配值和引用并不太复杂.尽管如此,Spring 的命名空间p 提供了另一种Bean 属性的装配方式,该方式不需要配置如 ...

  6. Spring笔记③--spring的命名空间

    p:命名空间: xmlns:p="http://www.springframework.org/schema/p" 作用:简化在xml配置bean的属性 在<bean> ...

  7. Spring依赖注入 — util命名空间配置

    要使用<util>标签,必须在XML中加入util名称空间(namespace): xmlns:util="http://http://www.springframework.o ...

  8. spring util list

    spring 3.0 after <util:list/>元素 借助<list/>元素,开发者能够定义java.util.List集合.下面摘录了list.xml中的配置信息. ...

  9. IDEA引入spring的命名空间

    我们在写spring的配置文件的时候,有的时候可能会用到 P 标签,然后我们发现自己并没有p标签啊,那么我们一起来看我是怎么解决的. 首先在我们的xml文件的首部添上这句话: xmlns:contex ...

随机推荐

  1. 使用CSS来显示XML

    实现效果学号 姓名 班级 课程 教师 表格背景设为绿色,单元格居中显示 学号部分,蓝色字体,16磅大小: 姓名部分红色字体,带有下划线,12磅大小 班级课程名,教师,绿色字体,12磅大小 XML代码: ...

  2. thinkphp 查询

    一.普通查询方式 a.字符串 $arr=$m->where("sex=0 and username='gege'")->find(); b.数组 $data['sex' ...

  3. LINUX下查看CPU使用率的命令[Z]

    1.top 使用权限:所有使用者 使用方式:top [-] [d delay] [q] [c] [S] [s] [i] [n] [b] 说明:即时显示process的动态 d :改变显示的更新速度,或 ...

  4. 修改oracle内存

    [oracle@bi11g bin]$ ./sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 1618:39:36 2 ...

  5. 加密传输SSL协议2_传统加密

    原本到了睡觉的时间,但是做完了SSL的笔记还有GCC和Oracle等的好多的笔记,所以刻苦一点. The Priciple of Encryption/Decryption --conventiona ...

  6. Linux学习之rcp命令

    rcp代表“remote file copy”(远程文件拷贝).该命令用于在计算机之间拷贝文件.rcp命令有两种格式.第一种格式用于文件到文件的拷贝:第二种格式用于把文件或目录拷贝到另一个目录中. 1 ...

  7. Git 系列(四):在 Git 中进行版本回退

    在这篇文章中,你将学到如何查看项目中的历史版本,如何进行版本回退,以及如何创建 Git 分支以便你可以大胆尝试而不会出现问题. 在你的 Git 项目的历史中,你的位置就像是摇滚专辑中的一个片段,由一个 ...

  8. ■[iOS] Interface type cannot be statically allocated の原因と対応

    iOSでの開発をしていると.表題のエラーが起こる場合があります. 原因 変数の型が静的割り当てになっていることが原因. 対応 変数の型をポインタ型にすると.エラーがなくなります.(変数の前に*をつける ...

  9. Scala的类中定义内部类实战

    scala独特之处在于可以在类中定义内部类,起到对外屏蔽作用. 类中默认都是public权限.后面将讲解如何引入接口,scala中的接口与java点区别.特质/接口(Trait)

  10. J2SE知识点摘记(二十)

    List 1.3.1        概述 前面我们讲述的Collection接口实际上并没有直接的实现类.而List是容器的一种,表示列表的意思.当我们不知道存储的数据有多少的情况,我们就可以使用Li ...