修改properties文件不重启应用服务器

在开发应用时需要在properties文件里面写一个开关,手动禁用或启用程序的某项功能。百度了下,大部分人认为不可能实现此功能,还说了很多原理。不罗嗦,直接说解决方案。

我是使用jfinal来开发的,因此下面的代码片段,基于jfinal的prokit等文件的修改。

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));

            }  

注:以上代码需要commons-lang2.6 和commons-configuartion1.10 的支持。

你可能感兴趣的:(修改properties文件不重启应用服务器)