1、
/** * 加载配置参数 */ public abstract class PropertyUtils { protected abstract ResourceBundle getResource(); /** * 获取Property文件中key对应的value * @param key * @param params * @return */ final public String getMessage(String key, Object... params) { if (params != null && params.length > 0) { return String.format(getResource().getString(key), params); } return getResource().getString(key); }
/*
* 读取message.properties工具类 */ public class AppPropertyUtil extends PropertyUtils { private static ResourceBundle resourceBundle; public static AppPropertyUtil instance; @Override protected ResourceBundle getResource() { if (resourceBundle != null) { return resourceBundle; }else { //eq:"config/heart" resourceBundle = ResourceBundle.getBundle("config/message"); } return resourceBundle; } static { instance = new AppPropertyUtil(); } }