标签:
<?xml version="1.0" encoding="GBK"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<!-- 驱动Spring调用messageSource Bean的setBasenames()方法,
该方法需要一个数组参数,使用list元素配置多个数组元素 -->
<property name="basenames">
<list>
<value>message1</value>
<!-- 如果有多个资源文件,全部列在此处 -->
</list>
</property>
</bean>
</beans>
package lee;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.*;
public class SpringTest
{
public static void main(String[] args)throws Exception
{
// 实例化ApplicationContext
ApplicationContext ctx = new
ClassPathXmlApplicationContext("beans.xml");
// 使用getMessage()方法获取本地化消息。
// Locale的getDefault方法返回计算机环境的默认Locale
String hello = ctx.getMessage("hello" , new String[]{"孙悟空"}
, Locale.getDefault());
String now = ctx.getMessage("now" , new Object[]{new Date()}
, Locale.getDefault());
// 打印出两条本地化消息
System.out.println(hello);
System.out.println(now);
}
}
标签:
原文地址:http://www.cnblogs.com/ssslinppp/p/4378085.html