/** * */ package com.sprucetec.tms.fee.utils; import java.io.IOException; import java.util.ArrayList; import java.util.Properties; import org.apache.log4j.Logger; import org.springframework.core.io.support.PropertiesLoaderUtils; /** * * Title: ConfigFileUtils.java * Description: * Copyright: Copyright (c) 2016 * Company: 北京云杉世界信息技术有限公司 * * @author * 2016年3月2日 */ public class TmsConfigFileUtils { private static final Logger logger = Logger.getLogger(TmsConfigFileUtils.class); /** * * @author meicai * 2016年3月2日 * @param nodeName * @return */ public static ArrayList getShardconfig(String nodeName) { String configName = "shard.properties"; String result = pubReadConfig(configName, nodeName); if (result == null) { result = pubReadConfig("prop/" + configName, nodeName); } String[] nodes = result.split(","); ArrayList nodeList = new ArrayList (); for(String node : nodes){ nodeList.add(Long.valueOf(node)); } return nodeList; } /** * 通用读取方法 * * @param configName * @param nodeName * @return */ public static String pubReadConfig(String configName, String nodeName) { Properties props = new Properties(); while (true) { try { props = PropertiesLoaderUtils.loadAllProperties(configName); return (String) props.get(nodeName); } catch (IOException e) { logger.error("ReadConfigException", e); System.out.println(e.getMessage()); } } } }