在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. ORA-32001: 已请求写入 SPFILE, 但是在启动时未指定 SPFILE

    SQL> alter system set smtp_out_server='smtp.126.com' scope=both;alter system set smtp_out_server= ...

  2. oracle中查找执行效率低下的SQL

    v$sqltext:存储的是完整的SQL,SQL被分割 v$sqlarea:存储的SQL 和一些相关的信息,比如累计的执行次数,逻辑读,物理读等统计信息(统计) v$sql:内存共享SQL区域中已经解 ...

  3. Neo4j简介

    Neo4j简介 发表于2013年3月16日 11:52 p.m.    位于分类图数据库与图并行计算 现实中很多数据都是用图来表达的,比如社交网络中人与人的关系.地图数据.或是基因信息等等.RDBMS ...

  4. CSS的“层叠”规则的总结

    当你随机打开一个页面,查看源代码,你会发现,同一个元素,不止有一个CSS选择器及对应的样式.而一个元素只能应用一个样式,那么一堆样式中究竟是应用哪一个呢?这就涉及到CSS的层叠规则了.下面就来总结下C ...

  5. EC读书笔记系列之10:条款16、17

    条款18 让接口容易被正确使用,不易被误用 记住: ★“促进正确使用”的办法包括接口的一致性,以及与内置类型的行为兼容 ★“阻止误用”的办法包括建立新类型.限制类型上的操作,束缚对象值,以及消除客户的 ...

  6. Java Eclipse常规设置

    改变字体大小 eclipse英文版中如何去修改字体及方法?首先打开eclipse中,按下面的方法即可菜单项:window ->preferences -> general -> ap ...

  7. op cache config

    [opcache] ; dll地址 zend_extension=php_opcache.dll ; 开关打开 opcache.enable=1 ; 开启CLI opcache.enable_cli= ...

  8. Android StrictMode介绍

    转:http://www.blueowls.net/android-strictmode%E4%BB%8B%E7%BB%8D/ /** * enables "strict mode" ...

  9. mysql函数操作(6)

    <?php try{ $dbh = new PDO('mysql:dbname=testdb;host=localhost', 'mysql_user', 'mysql_pwd'); }catc ...

  10. substr(dirname(__FILE__))

    这是discuz中定义论坛安装根目录的一个常量.现在我们就来分析一下这个很简单但是非常实用的常量.     define('DISCUZ_ROOT', substr(dirname(__FILE__) ...