package com.olm.util; import lombok.extern.slf4j.Slf4j; import java.io.InputStream; import java.util.Properties; @Slf4j public class Configure { private static final Properties config; static { log.info("初始化加载配置!"); String filePath = "config.properties"; config = new Properties(); try { ClassLoader CL = Configure.class.getClassLoader(); InputStream in; if (CL != null) { in = CL.getResourceAsStream(filePath); } else { in = ClassLoader.getSystemResourceAsStream(filePath); } config.load(in); assert in != null; in.close(); } catch (Exception e) { log.error("加载配置异常", e); } } public static String getValue(String key) { if (config.containsKey(key)) { return config.getProperty(key); } else { return ""; } } public static int getValueInt(String key) { String value = getValue(key); int valueInt = 0; try { valueInt = Integer.parseInt(value); } catch (NumberFormatException e) { e.printStackTrace(); return valueInt; } return valueInt; } }