applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="basename">
<value>rockie</value>
</property>
</bean></beans>
rockie_zh_CN.properties
org.rockie=welcome{0}to myBlog,time:{1}...
rockie_en_US.properties
org.rockie=欢迎{0}到该博客,时间:{1}...
TestMain.java
package org.rockie;
import java.util.Date;
import java.util.Locale;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class TestMain {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
ApplicationContext context=new FileSystemXmlApplicationContext("org/rockie/applicationContext.xml");
Object object[]=new Object[]{"rockie",(new Date().toString())};
System.out.println(context.getMessage("org.rockie",object,Locale.US));
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)