修改properties文件不重啓應用服務器

在開發應用時須要在properties文件裏面寫一個開關,手動禁用或啓用程序的某項功能。百度了下,大部分人認爲不可能實現此功能,還說了不少原理。不羅嗦,直接說解決方案。spa

我是使用jfinal來開發的,所以下面的代碼片斷,基於jfinal的prokit等文件的修改。開發

PropertiesConfiguration cfg = new PropertiesConfiguration(fileName);get

            cfg.setReloadingStrategy(new FileChangedReloadingStrategy());it

            cfg.setEncoding(encoding);io

            cfg.load();原理

            Iterator<String> iterator = cfg.getKeys();百度

            properties = new Properties();coding

            while(iterator.hasNext()){file

                String key = iterator.next();程序

                properties.setProperty(key,cfg.getString(key));

            }  

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

相關文章
相關標籤/搜索