spring中的ResourceBundleMessageSource
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的更多相关文章
- spring中基础核心接口总结
spring中基础核心接口总结理解这几个接口,及其实现类就可以快速了解spring,具体的用法参考其他spring资料 1.BeanFactory最基础最核心的接口重要的实现类有:XmlBeanFac ...
- spring中MessageSource的配置使用方法3--ResourceBundleMessageSource【转】
本文转载仅供自己学习收录,不做任何商业用途,如有需要请访问原地址:http://blog.csdn.net/qyf_5445/article/details/8124431 ApplicationCo ...
- spring中MessageSource的配置使用方法3--ResourceBundleMessageSource
ApplicationContext接口扩展了MessageSource接口,因而提供了消息处理的功能(i18n或者国际化).与HierarchicalMessageSource一起使用,它还能够处理 ...
- Spring中的容器
1.Spring容器 Spring容器最基本的接口就是BeanFactory, 负责配置,创建和管理bean.我们通常不直接使用BeanFactory接口,而是使用其子接口ApplicationCon ...
- Velocity初探小结--Velocity在spring中的配置和使用
最近正在做的项目前端使用了Velocity进行View层的数据渲染,之前没有接触过,草草过了一遍,就上手开始写,现在又回头细致的看了一遍,做个笔记. velocity是一种基于java的模板引擎技术, ...
- Spring中Bean的作用域、生命周期
Bean的作用域.生命周期 Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例).protot ...
- Spring中Bean的实例化
Spring中Bean的实例化 在介绍Bean的三种实例化的方式之前,我们首先需要介绍一下什么是Bean,以及Bean的配置方式. 如果 ...
- 模拟实现Spring中的注解装配
本文原创,地址为http://www.cnblogs.com/fengzheng/p/5037359.html 在Spring中,XML文件中的bean配置是实现Spring IOC的核心配置文件,在 ...
- Spring中常见的bean创建异常
Spring中常见的bean创建异常 1. 概述 本次我们将讨论在spring中BeanFactory创建bean实例时经常遇到的异常 org.springframework.beans.fa ...
随机推荐
- 【Unity3D】Unity自带组件—完成第一人称人物控制
1.导入unity自带的Character Controllers包 2.可以看到First Person Controller组件的构成 Mouse Look() : 随鼠标的移动而使所属物体发生旋 ...
- system函数的总结
最近在看APUE第10章中关于system函数的POSIX.1的实现.关于POSIX.1要求system函数忽略SIGINT和SIGQUIT,并且阻塞信号SIGCHLD的论述,理解得不是很透彻,本文就 ...
- Linux User's Manual IOSTAT
IOSTAT(1) Linux User's Manual IOSTAT(1) NAME iostat - Report Central Processing Unit (CPU) statistic ...
- C#中常见的winform控件命名规范
我们知道Button 常常简称为btn,那么Winform中的其它控件呢,这篇文章在C#的winform控件命名规范 的基础上对一些控件的名称的简称进行了整理. 1. 标准控件 NO. 控件类型简写 ...
- logback.xml配置
一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文 ...
- CXF之一 基础理论介绍
WebService介绍 WebService让一个程序可以透明地调用互联网程序,不用管具体的实现细节.只要WebService公开了服务接口,远程客户端就可以调用服务.WebService是基于 ...
- [持续更新]android stduio的一些小技巧
1.导入第三方jar 无法和eclipse一样可以直接刷新就可以导入libs里的jar,要到jar文件上右键按add jar. 2.其他依赖项目里有support-v4包的时候 在Libs里还是要有s ...
- UITableView 点击展开的实现
推介看下这里的 内容 http://www.cnblogs.com/kenshincui/p/3931948.html IOS8 above UITabliViewCell 利用 autolayou ...
- <译>Selenium Python Bindings 6 - WebDriver API
本章涉及Selenium WebDriver的所有接口. Recommended Import Style 推荐的导入风格如下: from selenium import webdriver 然后,你 ...
- .NET开发工具
1.Two monitors 2.Visual Studio 3.TestDriven.NET 4.JetBrains ReSharper 5.VS样式 https://studiostyl.es/