| package com.xcong.excoin.utils; | 
|   | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.context.MessageSource; | 
| import org.springframework.context.NoSuchMessageException; | 
| import org.springframework.context.i18n.LocaleContextHolder; | 
| import org.springframework.stereotype.Component; | 
|   | 
| /** | 
|  * @author wzy | 
|  * @date 2020-05-05 16:57 | 
|  **/ | 
| @Component | 
| @Slf4j | 
| public class MessageSourceUtils { | 
|   | 
|     private static MessageSource messageSource; | 
|   | 
|     public MessageSourceUtils(MessageSource messageSource) { | 
|         MessageSourceUtils.messageSource = messageSource; | 
|     } | 
|   | 
|     public static String getString(String key) { | 
|         try { | 
|             return messageSource.getMessage(key, null, LocaleContextHolder.getLocale()); | 
|         } catch (NoSuchMessageException e) { | 
|             log.error("#获取国际化异常#", e); | 
|             return key; | 
|         } | 
|     } | 
| } |