我想在 Spring 应用程序中维护一个应用程序属性列表,例如服务端点、应用程序变量等。这些属性应该能够动态更新(可能由系统管理员通过网页)。
spring有内置的功能来完成这个要求吗?
我不确定 spring 是否有动态更新属性文件的实现。
您可以执行类似读取属性文件之类的操作FileInputStream
into a Properties
目的。然后您将能够更新属性。稍后您可以使用以下命令将属性写回同一文件FileOutputStream
.
// reading the existing properties
FileInputStream in = new FileInputStream("propertiesFile");
Properties props = new Properties();
props.load(in);
in.close();
// writing back the properties after updation
FileOutputStream out = new FileOutputStream("propertiesFile");
props.setProperty("property", "value");
props.store(out, null);
out.close();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)