简而言之就是读取properties配置文件中的数据。该配置文件以key-value值存储。ApplicationContext接口继承MessageSource接口,因此具备国际化功能。
MessageSource接口中定义了3个用于国际化的方法:
String getMessage(XXX);
在spring的配置文件中如下配置:
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>org/springframework/security/messages</value>
<value>messages</value>
<value>adc</value>
</list>
</property>
</bean>
资源文件如:
hello=welcome,{0}
now=now is {0}
程序中如下:
@Resource
private MessageSource messageSource;
String msg = messageSource.getMessage("hello","test", null);