International support: for applications that need to support different language Environments, you can configure all language information through independent resource files and convert different language versions.
Bean for configuring messageSource
<Bean id = "messageSource" class = "org. springframework. context. support. ResourceBundleMessageSource">
<Property name = "basenames">
<List>
<Value> messages </value>
</List>
</Property>
</Bean>
Define two resource files: messages_zh_CN.properties (Chinese) and messages_en_US.properties (English)
Here, messages _ ** is based on the message defined in the bean file.
// Messages_zh_CN
Userinfo = \ u5F53 \ u524D \ u7528 \ u6237 \ uFF1A [{0}] \ u767B \ u5F55 \ u65F6 \ u95F4 \ uFF1A [{1}]
// Messages_en_US.properties
Userinfo = Current loggin user: [{0}] login time: [{1}]
Test class
Package test2;
Import java. util. Calendar;
Import java. util. Locale;
Import org. springframework. context. ApplicationContext;
Import org. springframework. context. support. FileSystemXmlApplicationContext;
Public class testDemo {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
ApplicationContext ctx = new FileSystemXmlApplicationContext ("bean. xml ");
Object [] arg = new Object [] {
"Erica", Calendar. getInstance (). getTime ()
};
String msg1 = ctx. getMessage ("userinfo", arg, Locale. getDefault ());
String msg2 = ctx. getMessage ("userinfo", arg, Locale. US );
System. out. println (msg1 );
System. out. println (msg2 );
}
Author: y200930690129