<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list><!-- 配置文件名 -->
<value>test</value>
<value>test1</value>
</list>
</property>
</bean>
[b]test.properties配置文件[/b]
[color=olive]message=Alligators rock\![/color]
[b]test1.properties配置文件[/b]
[color=olive]argument.required=The '{0}' argument is required.[/color]
类文件代码 (一)
MessageSource resources = new ClassPathXmlApplicationContext("applicationContext.xml");
String message = resources.getMessage("message", null, "Default", null);
输出: [b]Alligators rock![/b]
类文件代码 (二)
MessageSource resources = new ClassPathXmlApplicationContext("applicationContext.xml");
String message = resources.getMessage("argument", new Object [] {"userDao"}, "Required", Locale.UK);
输出: [b]The userDao argument is required.[/b]