JAVA中如何重新加载.properties文件,使其他引用实时改变?

如题所述

       * Spring 提供的 PropertiesLoaderUtils 允许您直接通过基于类路径的文件地址加载属性资源
      
         * 最大的好处就是:实时加载配置文件,修改后立即生效,不必重启
        
         */
        private static void springUtil(){
                Properties props = new Properties();
                while(true){
                        try {
                                props=PropertiesLoaderUtils.loadAllProperties("message.properties");
                                for(Object key:props.keySet()){
                                        System.out.print(key+":");
                                        System.out.println(props.get(key));
                                }
                        } catch (IOException e) {
                                System.out.println(e.getMessage());
                        }
                        try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
                }
        }

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网