1 首先创建两个资源文件 
   messages_en_US.properties 
customer.name=Yong Mook Kim, age : {0}, URL : {1} 
messages_zh_CN.properties 
  customer.name=\ufeff\u6768\u6728\u91d1, age : {0}, URL : {1}

2 bean文件的设置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>locale\customer\messages</value>
</property>
</bean> </beans>

其中basename指出了资源文件的位置

3 测试

public static void main(String[] args) {

        ApplicationContext context
= new ClassPathXmlApplicationContext("locale.xml"); String name = context.getMessage("customer.name",
new Object[] { 28,"http://www.eeee.com" }, Locale.US); System.out.println("Customer name (English) : " + name); String namechinese = context.getMessage("customer.name",
new Object[] {28, "http://www.eeee.com" },
Locale.SIMPLIFIED_CHINESE); System.out.println("Customer name (Chinese) : " + namechinese); }

4 另外一个ReloadableResourceBundleMessageSource,主要是用来定时刷新资源文件,可以不重启动 
    增加的属性为:  <property name="cacheSeconds" value="3000" /> 
   以秒为单位,如果-1表示用不刷新

参考:http://blog.csdn.net/jackyrongvip/article/details/9218325

spring中的ResourceBundleMessageSource的更多相关文章

  1. spring中基础核心接口总结

    spring中基础核心接口总结理解这几个接口,及其实现类就可以快速了解spring,具体的用法参考其他spring资料 1.BeanFactory最基础最核心的接口重要的实现类有:XmlBeanFac ...

  2. spring中MessageSource的配置使用方法3--ResourceBundleMessageSource【转】

    本文转载仅供自己学习收录,不做任何商业用途,如有需要请访问原地址:http://blog.csdn.net/qyf_5445/article/details/8124431 ApplicationCo ...

  3. spring中MessageSource的配置使用方法3--ResourceBundleMessageSource

    ApplicationContext接口扩展了MessageSource接口,因而提供了消息处理的功能(i18n或者国际化).与HierarchicalMessageSource一起使用,它还能够处理 ...

  4. Spring中的容器

    1.Spring容器 Spring容器最基本的接口就是BeanFactory, 负责配置,创建和管理bean.我们通常不直接使用BeanFactory接口,而是使用其子接口ApplicationCon ...

  5. Velocity初探小结--Velocity在spring中的配置和使用

    最近正在做的项目前端使用了Velocity进行View层的数据渲染,之前没有接触过,草草过了一遍,就上手开始写,现在又回头细致的看了一遍,做个笔记. velocity是一种基于java的模板引擎技术, ...

  6. Spring中Bean的作用域、生命周期

                                   Bean的作用域.生命周期 Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例).protot ...

  7. Spring中Bean的实例化

                                    Spring中Bean的实例化 在介绍Bean的三种实例化的方式之前,我们首先需要介绍一下什么是Bean,以及Bean的配置方式. 如果 ...

  8. 模拟实现Spring中的注解装配

    本文原创,地址为http://www.cnblogs.com/fengzheng/p/5037359.html 在Spring中,XML文件中的bean配置是实现Spring IOC的核心配置文件,在 ...

  9. Spring中常见的bean创建异常

    Spring中常见的bean创建异常 1. 概述     本次我们将讨论在spring中BeanFactory创建bean实例时经常遇到的异常 org.springframework.beans.fa ...

随机推荐

  1. WebView 中重写javascript 常用函数

    常规函数   javascript 常规函数包括以下3个函数:  (1)alert函数:显示一个警告对话框,包括一个OK按钮. 对应:http://www.dreamdu.com/javascript ...

  2. 组以逗号分隔的子串及跨平update join

    下列语句可以对组以逗号分隔的子串 set @device_cd_array += ', ' set @device_cd_array += @nodeid ,, '') update时要join表要先 ...

  3. ioctl()获取本地网卡设备信息

    获得eth0接口所有信息: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #inclu ...

  4. xml-xml试题

    ylbtech-doc:xml-xml试题 xml试题 1.A,xml试题返回顶部 01.{XML题目}关于XML声明正确的是.(选择1项) A)<!xml version=”1.0”!> ...

  5. android 布局居中

    android:layout_alignParentLeft="true" 位于父容器左上角 android:layout_alignParentBottom, android:l ...

  6. android sensor传感器系统架构初探

    http://blog.csdn.net/qianjin0703/article/details/5942579 http://blog.chinaunix.net/uid-28621021-id-3 ...

  7. res/raw和assets的 区别

    res/raw和assets的相同点: 两者目录下的文件在打包后会原封不动的保存在apk包中,不会被编译成二进制. res/raw和assets的不同点: 1.res/raw中的文件会被映射到R.ja ...

  8. 微软Azure开始支持Docker技术

    前一段时间还在与微软的技术人员讨论媒体转换服务的效率问题,如果应用 Docker将会有质的提高,没想到国外的Azure已经开始支持了,相信国内Azure支持也不远了.微软正在努力确保Azure成为开发 ...

  9. Azure终于支持大容量虚拟机了-最高32核,448G内存

    Azure终于支持大容量虚拟机了-最高32核,448G内存 最近微软Azure虚拟机旗下的大容量G系列虚拟机通用版本正式上线.G系列虚拟机方案提供公有云领域最大的内存容量.最强处理能力以及空间可观的本 ...

  10. [转] Web前端优化之 Server篇

    原文链接: http://lunax.info/archives/3093.html Web 前端优化最佳实践第二部分面向 Server .目前共计有 6 条实践规则.[注,这最多算技术笔记,查看最原 ...