Spring 配置标签——util标签

 
 

一、配置applicationContext.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <bean id="blankDisc" class="com.hk.BlankDisc" c:_0="aaaa" c:_1="111"/>
<bean id="person" class="com.hk.Person">
<property name="list" ref="list"/>
<property name="map" ref="map"/>
<property name="set" ref="set"/>
</bean> <util:list id="list">
<value>listValue1111</value>
<value>listValue2222</value>
<value>listValue3333</value>
</util:list> <util:map id="map">
<entry key="map1" value="11111"/>
<entry key="map2" value="22222"/>
<entry key="map3" value="33333"/>
</util:map> <util:set id="set">
<value>setValue1</value>
<value>setValue2</value>
<value>setValue3</value>
</util:set>
</beans>

二、配置javabean

package com.hk;

import java.util.List;
import java.util.Map;
import java.util.Set; /**
* User: muyunlong
* Date: 2017/8/6 上午7:53
* version: 1.0
*/
public class Person { private List list;
private Set set;
private Map map; public void setList(List list) {
this.list = list;
} public void setSet(Set set) {
this.set = set;
} public void setMap(Map map) {
this.map = map;
} public List getList() {
return list;
} public Set getSet() {
return set;
} public Map getMap() {
return map;
}
}

三、新建测试类

package com.hk;

import javafx.application.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.List; /**
* Hello world!
*
*/
public class App
{
@Autowired
private static CompactDisc compactDisc; public static void main( String[] args )
{
ApplicationContext application = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
CompactDisc c = (CompactDisc) application.getBean("blankDisc");
c.play();
Person p = (Person) application.getBean("person");
List list = p.getList();
for (int i = 0; i < list.size(); i++) {
String aa = (String) list.get(i);
System.out.println(aa);
} } private void play(){
compactDisc.play();
}
}

四、总结

spring util-命名空间中的元素

元素  描述
<util:constant> 引用某个类型public static 域,并将其暴露为bean
<util:list> 创建一个java.util.list类型的bean,其中包含值或者引用
<util:map> 创建一个java.util.map类型的bean,其中包含值或者引用
<util:properties> 创建一个java.util.properties类型的bean
<util:property-path> 引用一个属性(或内嵌属性),并将其暴露为bean
<util:set> 创建一个java.util.set类型的bean,其中包含值或者引用

Spring 配置标签——util标签的更多相关文章

  1. Dubbo中对Spring配置标签扩展

    Spring提供了可扩展Schema的支持,完成一个自定义配置一般需要以下步骤: 设计配置属性和JavaBean 编写XSD文件 编写NamespaceHandler和BeanDefinitionPa ...

  2. Spring+shiro配置JSP权限标签+角色标签+缓存

    Spring+shiro,让shiro管理所有权限,特别是实现jsp页面中的权限点标签,每次打开页面需要读取数据库看权限,这样的方式对数据库压力太大,使用缓存就能极大减少数据库访问量. 下面记录下sh ...

  3. Spring配置之标签的三两事

    今天看到项目的配置,看后就当是复习了.懵懵懂懂工作两年,感觉虽然自己一直在使用spring作为工具,但是也没有涉及到spring的方方面面,今天的研究从一次无意的自动补全开始,还是那句话,不爱研究的程 ...

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

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

  5. Spring MVC -- JSP标准标签库(JSTL)

    JSP标准标签库(JavaServer Pages Standard Tag Library,JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能.JSTL支持通用的.结构化的任务,比如迭 ...

  6. spring整合freemarker 自定义标签

    1.自定义标签实现 TemplateDirectiveModel 接口 2.spring 配置,注意标红的两行 <bean id="freemarkerConfig" cla ...

  7. 03_MyBatis基本查询,mapper文件的定义,测试代码的编写,resultMap配置返回值,sql片段配置,select标签标签中的内容介绍,配置使用二级缓存,使用别名的数据类型,条件查询ma

     1 PersonTestMapper.xml中的内容如下: <?xmlversion="1.0"encoding="UTF-8"?> < ...

  8. 日常踩坑笔记:spring的context:property-placeholder标签

    背景: 原来的项目一直跑着没有问题,今天突然想在原有项目的基础上,加上redis进行数据的缓存,原来项目的架构就是传统的SSM框架,于是,大刀阔斧的开始改装了... 编写redis的配置文件——red ...

  9. 6.1 如何在spring中自定义xml标签

    dubbo自定义了很多xml标签,例如<dubbo:application>,那么这些自定义标签是怎么与spring结合起来的呢?我们先看一个简单的例子. 一 编写模型类 package ...

随机推荐

  1. hdu1693 Eat the Trees [插头DP经典例题]

    想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...

  2. 【codeforces 505C】Mr.Kitayuta,the Treasure Hunter

    [题目链接]:http://codeforces.com/problemset/problem/505/C [题意] 一开始你跳一步长度为d; 之后你每步能跳d-1,d,d+1这3种步数; 然后在路上 ...

  3. MySQL时间格式转换

    1.时间转换成特定字符串 例:select DATE_FORMAT(now(),'%Y-%m-%d %H:%i::%s'); --> '2019-10-16 10:59::18' 2.一种字符串 ...

  4. day1(老男孩-Python3.5-S14期全栈开发)

    作者:赵俊            发布日期:2019/10/18 一.第一个python程序 1.在解释器下写hello world程序运行,与运行外部文件方法 运行外部文件,必须在相应位置创建一个p ...

  5. js 获取复选框 和 并改变状态

    function checkAll() { var checkbox = document.getElementById('vegeids');// var boxes = document.getE ...

  6. LA5713 Qin Shi Huang's National Road System

    题目大意:秦始皇要在n个城市之间修筑一条道路使得任意两个城市均可连通.有个道士可以用法力帮忙修一条路.秦始皇希望其他的道路总长B最短且用法术连接的两个城市的人口之和A尽量大,因此下令寻找一个A / B ...

  7. Luogu P1462 通往奥格瑞玛的道路(最短路+二分)

    P1462 通往奥格瑞玛的道路 题面 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己 ...

  8. 基于PHP的一种Cache回调与自动触发技术

    $s = microtime(true); for($i=0; $iaaa($array, $array, $array); $data = a::bbb($array, $array, $array ...

  9. iview中table的render()函数

    Vue 推荐在绝大多数情况下使用 template 来创建你的 HTML.然而在一些场景中,你真的需要 JavaScript 的完全编程的能力,这就是 render 函数,它比 template 更接 ...

  10. JS---案例:无刷新评论---属于创建对象的案例拿出来复习

    案例:无刷新评论---属于创建对象的案例拿出来复习 创建行和单元格,添加到相应元素中,设置内容 createElement, appendChild,innerHTML <!DOCTYPE ht ...