@jFinal
你好向您请教一个问题,我单独使用PropKit读取一个配置问题,然后启动系统,配置文件里面有2种登录方式,需要管理员可配置。即设置为a则登录的时候使用a的方式验证,设置为b则使用b的方式验证。
现在问题如下:
系统启动后,修改配置文件不会立即生效,需要重启。调用PropKit.clear()也没有用。请问有什么好的处理方式吗?
-**--*-
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
已解决下面是方案:
使用commons-configuration1.10插件支持properties热加载。注意需要同时加入commons-lang2.6和commons-logging-1.1.1 .
改写了下jfinal的Prop
/**
* 重载
* @param fileName
* @param encoding
*/
public Prop(String fileName, String encoding ,boolean isReplace) {
InputStream inputStream = null;
try {
if (fileName == null)
throw new IllegalArgumentException("Properties file not found in classpath: " + fileName);
PropertiesConfiguration cfg = new PropertiesConfiguration(fileName);
cfg.setReloadingStrategy(new FileChangedReloadingStrategy());
cfg.setEncoding(encoding);
cfg.load();
Iterator<String> iterator = cfg.getKeys();
properties = new Properties();
while(iterator.hasNext()){
String key = iterator.next();
properties.setProperty(key,cfg.getString(key));
}
} catch (Exception e) {
throw new RuntimeException("Other error.", e);
}
finally {
if (inputStream != null) try {inputStream.close();} catch (IOException e) {e.printStackTrace();}
}
}