import java.util.Enumeration; import java.util.ResourceBundle; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class PropertiesUtil { private static final Logger log = LoggerFactory.getLogger(PropertiesUtil.class); public static ConcurrentMap< String, String > appExceptionMessageMap = new ConcurrentHashMap< String, String >(); public static ConcurrentMap responseMessageMap = new ConcurrentHashMap(); public static ConcurrentMap interfaceAuthorityMap = new ConcurrentHashMap(); public static ConcurrentMap configMap = new ConcurrentHashMap(); static { init(); } private static void init(){ try{ ResourceBundle exceptionMessage = ResourceBundle.getBundle("props/error-message"); ResourceBundle responseMessage = ResourceBundle.getBundle("props/response-message"); ResourceBundle interfaceAuthority = ResourceBundle.getBundle("props/interface-authority"); ResourceBundle config = ResourceBundle.getBundle("props/config"); initConfig(exceptionMessage,appExceptionMessageMap); initConfig(responseMessage,responseMessageMap); initConfig(interfaceAuthority,interfaceAuthorityMap); initConfig(config, configMap); } catch (Throwable t){ log.error("cofig init error .............",t); } } private static void initConfig(ResourceBundle resourceBundle,ConcurrentMap map){ Enumeration< String > e = resourceBundle.getKeys(); while( e.hasMoreElements() ) { String key = e.nextElement(); map.put( key, resourceBundle.getString( key ) != null ? resourceBundle.getString( key ) .trim() : null ); } } }
properties java 工具_java Properties工具
最新推荐文章于 2022-10-28 10:18:15 发布