Spring《七》ApplicationContext
1、国际化支持
getMessage()提供了国际化支持。
Bean中必须定义为messageSource。
<bean id="messageSource" class="org.springfarmework.comtext.support.ResourceBundleMessage-Source">
<property name="basename"> //固定
<value>messages</value>//message.properties或者message.calss 国际化信息被定义在这样的文件中
</property>
</bean>
内容
HelloWorld=问候语:{0} 问候时间:{1}//0、1代表从外部传入的信息
解决编码问题:
native2ascii messages.properties messages.txt
2、资源访问
getResource()提供了资源获取支持。
路径指定classpath(项目根目录)、file(全路径)或http、相对路径
classpath:messages.properties
file:d:/eclipse/messages.properties
"WEB-INF/src/messages.properties"
使用代码:
ApplicationContext actx=new FileSystemXmlApplicationContext("config.xml");
Resource resource=actx.getResource("classpath:messages.properties");
3、事件传递
ApplicationEvent:定义自定义的事件。
ApplicationListener :用于接收事件。
ApplicationContextAware:用于将自定义事件传递给事件通道。
实现该接口主要是获取到applicationContext 句柄,该句柄提供了插入事件的方法。
具体代码:
LogEvent event=new LogEvent(log);
this.applicationContext.publishEvent(event);
配置文档config.xml中增加bean
<bean id="listener" class="com.gc.action.LogListener">
Spring《七》ApplicationContext的更多相关文章
- Spring中ApplicationContext对事件的支持
Spring中ApplicationContext对事件的支持 ApplicationContext具有发布事件的能力.这是因为该接口继承了ApplicationEventPublisher接口. ...
- Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式
转自:http://chinazhaokeke.blog.163.com/blog/static/109409055201092811354236 Spring获取ApplicationContex ...
- Spring容器-ApplicationContext的单例设计
Spring容器-ApplicationContext的单例设计 每次通过new创建一个ApplicationContext容器,都会执行refresh方法,看源代码了解到这个refresh方法会 ...
- Spring的applicationContext.xml文件
以下是详解Spring的applicationContext.xml文件代码:<!-- 头文件,主要注意一下编码 --><?xml version="1.0" e ...
- web.xml中配置Spring中applicationContext.xml的方式
2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...
- 怎么获取Spring的ApplicationContext
在 WEB 开发中,可能会非常少须要显示的获得 ApplicationContext 来得到由 Spring 进行管理的某些 Bean, 今天我就遇到了,在这里和大家分享一下, WEB 开发中,怎么获 ...
- Spring中ApplicationContext加载机制
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp33 加载器目前有两种选择:ContextLoaderListener和Co ...
- Spring初始化ApplicationContext为null
1. ApplicationContextAware初始化 通过它Spring容器会自动把上下文环境对象调用ApplicationContextAware接口中的setApplicationConte ...
- 获取spring的ApplicationContext几种方式【转】
转自:http://blog.sina.com.cn/s/blog_9c7ba64d0101evar.html Java类获取spring 容器的bean 常用的5种获取spring 中bean的方式 ...
- 关于Spring中applicationContext.xml配置错误“org/springframework/transaction/interceptor/TransactionInterceptor”的问题解决
问题描述: 在配置spring的applicationContext.xml中的默认事务管理器的时候可能会出现这样的错误: Error occured processing XML 'org/spri ...
随机推荐
- C#面对“重载”的Win 32 函数
在Win32 Api中有很多添加/设置函数在参数上支持多种不同类型的结构体.这些参数定义为LPVOID* 或者LPBYTE,LPVOID*一般由Win32 分配内存空间,在C#从通过System.In ...
- [Intermediate Algorithm] - Binary Agents
题目 传入二进制字符串,翻译成英语句子并返回. 二进制字符串是以空格分隔的. 提示 String.charCodeAt() String.fromCharCode() 测试用例 binaryAgent ...
- java 基础回顾1
整理----加自己理解------网上参考----- java封装理念 一 概念: 隐藏对象的属性和实现细节,仅供对外提供公共访问方式. 二 好处 1) 将变量隔离 2) 便于使用 3) 提高重 ...
- python排序sorted与sort比较 (转)
Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列. sorted(iterable,key=None,revers ...
- 用批处理实现垃圾文件清除/自动关机/清除copy病毒
晚上睡觉之前为了下emule经常使用命令shutdown,最近受一个小程序影响想做个自动关机的批处理文件免的麻烦!网上有高手做了个,不过运行时出 现一个绑定错误,at也不能执行,所以后来自己做了简化版 ...
- MySQL创建临时表
drop TEMPORARY table if EXISTS temp_table; create TEMPORARY table temp_table( id int not null, usern ...
- CentOS7.2安装nginx失败
错误提示: Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyu ...
- nyoj24-素数 距离问题
素数距离问题 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 现在给出你一些数,要求你写出一个程序,输出这些整数相邻最近的素数,并输出其相距长度.如果左右有等距离长度素数 ...
- 2019-04-16 sql tran and try catch :
begin try begin tran tran_addresource -- 标记事务的开始 delete rp insert into Cube.ResourcePool(ResourceTyp ...
- HDU - 1723 - Distribute Message
先上题目: Distribute Message Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...