spring util命名空间
在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命名空间的更多相关文章
- 曹工说Spring Boot源码(8)-- Spring解析xml文件,到底从中得到了什么(util命名空间)
写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...
- spring-第十篇之XML Schema的简化配置,p、c、util命名空间
1.p:命名空间 引入命名空间:xmlns:p="http://www.springframework.org/schema/p" 配置举例: <?xml version=& ...
- 什么是Spring的命名空间及使用Spring 的命名空间p 装配属性
这个就要从XML说了,Spring的配置管理可以利用XML方式进行配置,而XML里面就有命名空间这个概念..实际上就和标签的意思有点像 你给一个命名空间以后,这个XML文件里面就可以用那个命名空间上下 ...
- 使用Spring的命名空间p装配属性-摘自《Spring实战(第3版)》
使用<property>元素为Bean的属性装配值和引用并不太复杂.尽管如此,Spring的命名空间p提供了另一种Bean属性的装配方式,该方式不需要配置如此多的尖括号. 命名空间p的sc ...
- Spring P命名空间 02
P命名空间 装配属性 使用<property> 元素为Bean 的属性装配值和引用并不太复杂.尽管如此,Spring 的命名空间p 提供了另一种Bean 属性的装配方式,该方式不需要配置如 ...
- Spring笔记③--spring的命名空间
p:命名空间: xmlns:p="http://www.springframework.org/schema/p" 作用:简化在xml配置bean的属性 在<bean> ...
- Spring依赖注入 — util命名空间配置
要使用<util>标签,必须在XML中加入util名称空间(namespace): xmlns:util="http://http://www.springframework.o ...
- spring util list
spring 3.0 after <util:list/>元素 借助<list/>元素,开发者能够定义java.util.List集合.下面摘录了list.xml中的配置信息. ...
- IDEA引入spring的命名空间
我们在写spring的配置文件的时候,有的时候可能会用到 P 标签,然后我们发现自己并没有p标签啊,那么我们一起来看我是怎么解决的. 首先在我们的xml文件的首部添上这句话: xmlns:contex ...
随机推荐
- Oracle表管理
/*-----------------------创建和管理表-----------------------------*/一.Orcale之中的数据类型:1.NUMBER.DATE.VARCAHR. ...
- jquery 浏览器放大缩小函数resize
<script> $(function(){ $(window).resize(function(){ var _height = $(window).height(); var _con ...
- graph使泳道图的label横向显示
1.如果需要将label靠左边对齐,则必须重写底层源码 新增mxText的一个构造器,主要是增加了一个参数:x(代表当前的cell) function mxText(a, b, c, d, e, f, ...
- windows下如何安装配置mysql-5.7-m14-winx64(zip格式的安装)
win7 64位下如何安装配置mysql-5.7.4-m14-winx64 1. mysql-5.7.4-m14-winx64.zip下载 官方网站下载地址:http://dev.mysql.co ...
- 项目中经常用到的reset.css文件
html,body{width:100%; height: auto;} *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box- ...
- Linux学习之tail命令
tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新, ...
- Android中Dialog对话框
布局文件xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- OpenGL绘制环形渐变
开始看计算机图形学和OpenGL,挺有意思就自己随便写了一些效果. 以中间点坐标为圆心,计算每一点和圆心距离,根据距离算出一个RGB值,于是整体便呈现环形分布. 代码如下: #include < ...
- selenium webdriver 学习笔记(二)
selenium webdriver 一.定位一组元素: webdriver可以很方便的使用findElement 方法来定位某个物定的对象.不过有时候我们却要定位一组对象,这时候就需要使用findE ...
- 重置出错?微软Win10平板Surface Pro 4重装系统教程详解
重置出错?微软Win10平板Surface Pro 4重装系统教程详解 2015-12-11 15:27:30来源:IT之家作者:凌空责编:凌空 评论:65 Surface Pro 4系统重置出错该怎 ...