java Properties工具
2015-06-05 17:06
429 查看
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<String,String> responseMessageMap = new ConcurrentHashMap<String, String>();
public static ConcurrentMap<String,String> interfaceAuthorityMap = new ConcurrentHashMap<String, String>();
public static ConcurrentMap<String,String> configMap = new ConcurrentHashMap<String, String>();
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 );
}
}
}
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<String,String> responseMessageMap = new ConcurrentHashMap<String, String>();
public static ConcurrentMap<String,String> interfaceAuthorityMap = new ConcurrentHashMap<String, String>();
public static ConcurrentMap<String,String> configMap = new ConcurrentHashMap<String, String>();
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 );
}
}
}
相关文章推荐
- 顺手笔记---javac,javap,javah
- Java反射机制详解。
- javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher--转载
- Java语言描述:分支限界法之01背包问题
- Java for LeetCode 155 Min Stack
- Combination Sum III Leecode Java
- Java多线程用法解析
- java返回编码格式
- java 线程池优先级调度
- java琐碎
- Java for LeetCode 154 Find Minimum in Rotated Sorted Array II
- Java Word 转 Pdf
- JAVA设计模式初探之组合模式
- 简易Java(18):属性能否重写?为什么?
- 在java类中执行main方法时,报内存溢出
- netbeans下将所有jar包打成一个,俗称fat jar
- Struts2开发步骤
- 疯狂Java学习笔记(74)------------线程池
- Eclipse基于注解方式搭建ssh框架
- Eclipse 快捷键