public static void setPro(String key, String value) throws Exception {
Properties pps = new Properties();
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties");
pps.load(in);
//InputStream 转 OutputStream
OutputStream out = Tools.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"));
log.info("out:{}",out);
pps.setProperty(key, value);
log.info("pps:{}",pps);
pps.store(out, "Update " + key + "----value:"+value);
out.flush();
out.close();
}
配置文件在项目启动时首先读取,之后就不读取了。你项目启动后修改没用的。
想要用实时修改的配置,使用Apollo