globalization

Configuration file: application_context.xml

 <!-- Configure internationalization-->
     <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
      <!-- The file name where the internationalization information is located-->                    
      <property name=" basename" value="messages" />  
      <!-- If the corresponding code information cannot be found in the internationalized resource file, use this code as the name -->              
      <property name="useCodeAsDefaultMessage" value="true" / >          
 </bean>

 <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="zh_CN"></property>
 </bean>
 <bean id="SpringUtil" class="com.lty.common.util.SpringUtil"/>

 

java code:

package com.lty.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringUtil implements ApplicationContextAware {  
    private static ApplicationContext applicationContext;  
 
    public static ApplicationContext getApplicationContext() {  
        return applicationContext;  
    }  
 
    @Override 
    public void setApplicationContext(ApplicationContext arg0) throws BeansException {  
        applicationContext = arg0;  
    }  
 
    public static Object getBean(String id) {  
        Object object = null;  
        object = applicationContext.getBean(id);  
        return object;  
    }  

java value internationalization value:

System.out.println(SpringUtil.getApplicationContext().getMessage("LOGIN_IN", null, Locale.CHINA));

 

Internationalization properties file:

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326465747&siteId=291194637