public class PropertiesUtil { private static final Logger logger = LoggerFactory.getLogger(PropertiesUtil.class); private static Properties prop = null; private static String properPath = ConstantsDefine.CONFIG_PATH + "*.properties"; //静态块中的内容会在类被加载的时候先被执行 static { try { prop = new Properties(); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources = resolver.getResources(properPath); for (Resource resource : resources) { prop.load(new InputStreamReader(resource.getInputStream(), "UTF-8")); logger.info("{}|{} load complete!", properPath, resource.getFilename()); } } catch (Exception e) { e.printStackTrace(); } } //静态方法可以被类名直接调用 public static String getValue(String key) { return prop.getProperty(key); } //静态方法可以被类名直接调用 public static boolean getBooleanValue(String key) { return BooleanUtils.toBoolean(prop.getProperty(key)); } //静态方法可以被类名直接调用 public static int getIntegerValue(String key) { return Integer.parseInt(prop.getProperty(key)); } }