ApplicationContext接口继承MessageSource接口,在Spring中配置messageSource Bean时通常使用ResourceBundleMessageSource类。

<bean id="messageSource"

class="org.springframework.context.support.ResourceBundleMessageSource">

    <property name="basenames">

         <list>

             <value>message</value>

            <!--如果有多个资源文件,全部列在此处-->

         </list>

   </property>

</bean>

主程序核心:

ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml");

//使用getMessage方法获取本地化信息,Locale的getDefault方法

//返回计算机环境默认的Locale

String name = ctx.getMessage("资源文件属性名称", 数组名称,Locale.getDefault());

posted on 2014-03-28 13:41  倾国倾城  阅读(260)  评论(0编辑  收藏  举报