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的更多相关文章

  1. Spring中ApplicationContext对事件的支持

    Spring中ApplicationContext对事件的支持   ApplicationContext具有发布事件的能力.这是因为该接口继承了ApplicationEventPublisher接口. ...

  2. Spring获取ApplicationContext方式,和读取配置文件获取bean的几种方式

    转自:http://chinazhaokeke.blog.163.com/blog/static/109409055201092811354236  Spring获取ApplicationContex ...

  3. Spring容器-ApplicationContext的单例设计

    Spring容器-ApplicationContext的单例设计   每次通过new创建一个ApplicationContext容器,都会执行refresh方法,看源代码了解到这个refresh方法会 ...

  4. Spring的applicationContext.xml文件

    以下是详解Spring的applicationContext.xml文件代码:<!-- 头文件,主要注意一下编码 --><?xml version="1.0" e ...

  5. web.xml中配置Spring中applicationContext.xml的方式

    2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...

  6. 怎么获取Spring的ApplicationContext

    在 WEB 开发中,可能会非常少须要显示的获得 ApplicationContext 来得到由 Spring 进行管理的某些 Bean, 今天我就遇到了,在这里和大家分享一下, WEB 开发中,怎么获 ...

  7. Spring中ApplicationContext加载机制

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp33 加载器目前有两种选择:ContextLoaderListener和Co ...

  8. Spring初始化ApplicationContext为null

    1. ApplicationContextAware初始化 通过它Spring容器会自动把上下文环境对象调用ApplicationContextAware接口中的setApplicationConte ...

  9. 获取spring的ApplicationContext几种方式【转】

    转自:http://blog.sina.com.cn/s/blog_9c7ba64d0101evar.html Java类获取spring 容器的bean 常用的5种获取spring 中bean的方式 ...

  10. 关于Spring中applicationContext.xml配置错误“org/springframework/transaction/interceptor/TransactionInterceptor”的问题解决

    问题描述: 在配置spring的applicationContext.xml中的默认事务管理器的时候可能会出现这样的错误: Error occured processing XML 'org/spri ...

随机推荐

  1. Caffe2:使用Caffe构建LSTM网络

    前言: 一般所称的LSTM网络全叫全了应该是使用LSTM单元的RNN网络. 原文:(Caffe)LSTM层分析 入门篇:理解LSTM网络 LSTM的官方简介: http://deeplearning. ...

  2. VS2013配置编译Caffe-Win10_X64

    原文链接:http://blog.csdn.net/joshua_1988/article/details/45036993 有少量修改................ 2014年4月的时候自己在公司 ...

  3. 虚拟机+linux+大杂烩

    出于项目需要,需要用到linux系统.这玩意儿平时很少用,要说体验度还是windows更人性化一些. 1.虚拟机的安装,这个没说的,百度VMware直接下最新版安装就好. 2.接着是linux系统的安 ...

  4. JSP_内置对象_请求转发和请求重定向的区别

    请求重定向:客户端行为,response.sendRedirect(),从本质上将等同与两次请求,前一次请求request对象不会保存,地址栏的URL地址会改变. 请求转发:服务器行为,request ...

  5. 【转载】Java 集合详解

    转载:https://www.cnblogs.com/ysocean/p/6555373.html 一.集合的由来 通常,我们的程序需要根据程序运行时才知道创建多少个对象.但若非程序运行,程序开发阶段 ...

  6. 11.7 【Linq】在查询表达式和点标记之间作出选择

    11.7.1 需要使用点标记的操作 最明显的必须使用点标记的情形是调用 Reverse . ToDictionary 这类没有相应的查询表达式语法的方法.然而即使查询表达式支持你要使用的查询操作符,也 ...

  7. 用vue2.x注册一个全局的弹窗alert组件、confirm组件

    一.在实际的开发当中,弹窗是少不了的,默认系统的弹窗样式太丑,难以满足项目的实际需求,所以需要自己定义弹窗组件,把弹窗组价定义为全局的,这样减少每次使用的时候引入麻烦,节省开发时间.本文将分享如何定义 ...

  8. 【[Offer收割]编程练习赛15 B】分数调查

    [题目链接]:http://hihocoder.com/problemset/problem/1515 [题意] [题解] 带权并查集 relation[x]表示父亲节点比当前节点大多少; 对于输入的 ...

  9. Drop a database in MongoDB

    http://www.linuxask.com/questions/drop-a-database-in-mongodb Drop a database in MongoDB Answer: Assu ...

  10. UVA Jin Ge Jin Qu hao 12563

    Jin Ge Jin Qu hao (If you smiled when you see the title, this problem is for you ^_^) For those who ...