在beans.xml 文件增加Message class
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>message</value> //国际文件的名字
</list>
</property>
</bean>
message_en_US.properties
message_zn_ch.properties
两文件的名字,然后将文件发在src下
hello=welcom,{0}
now=now is :{0} //英文文件 后面的是站位符
hello=\u6B22\u8FCE\u4F60,{0}
now=\u73B0\u5728\u7684\u65F6\u95F4:{0} //中文文件
非英文全部要转化为,因为用的elipse 自动转换
然后
ApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml");
String hello=ctx.getMessage("hello", new String[]{"孙悟空"},Locale.getDefault(Locale.Category.FORMAT));
String now=ctx.getMessage("now", new Object[]{new Date()},Locale.getDefault(Locale.Category.FORMAT));
System.out.println(now);
System.out.println(hello);
Locale.Category.FORMAT 自动获取你电脑的语言属性 然后调用相关的国际文件
applicationContext 继承MessageSource 所以拥有国际化的功能
String getMessage(String code,Object[] args,Local loc)
String getMessage(String code,Object[] args,String default ,Local loc)