1,配置文件放在resource下
2,工具类
/** * 读取属性文件 * @author lr * @date 2019-05-29 14:38 */ public class PropertiesUtils { public static String getKey(String key) { Properties properties = new Properties(); InputStream resourceAsStream = PropertiesUtils.class.getClassLoader().getResourceAsStream("error/error.properties"); try { properties.load(resourceAsStream); } catch (IOException e) { e.printStackTrace(); } return properties.getProperty(key); } }
调用方式
public ExceptionBeanBuilder code(String code) { this.code = code; this.message = PropertiesUtils.getKey(code); return this; }