用 类名.class.getClassLoader().getResourceAsStream来获得config目录下的properties配置文件
public final class ConfigUtil {
private static Logger log = LoggerFactory.getLogger(ConfigUtil.class);
/**
* 属性对象
*/
private static Properties props;
/** 私有的构造函数 */
public ConfigUtil() {
props = null;
}
/**
* 根据属性key得到对应的属性值
*
* @param key
* 键名称
* @return
*/
public static String getPropsValueByKey(String filePath, String key) {
// if (props == null) {
props = new Properties();
InputStream resourceStream = ConfigUtil.class.getClassLoader().getResourceAsStream(filePath);
try {
props.load(resourceStream);
} catch (IOException e) {
String error = "配置文件工具类-根据属性key得到对应的属性值方法出现异常!";
log.error(error, e);
}
// }
return props.getProperty(key);
}
}