apache commons configuration自动加载修改的配置文件不用重启服务器

1. 引入jar包commons-configuration-1.6.jar;

2.  String file_name = (new Global()).getClass().getClassLoader().getResource("config/config.properties").getFile();
      file_name = file_name.replace("%20", " ");

      propconfig = new PropertiesConfiguration(file_name);
     //设置编码
     propconfig.setEncoding("UTF-8");
     //设置自动冲加载机制
     propconfig.setReloadingStrategy(new FileChangedReloadingStrategy());

    String mapRefresh = propconfig.getProperty("map.refreshTime").toString().trim();

    即可。

你可能感兴趣的:(apache commons configuration自动加载修改的配置文件不用重启服务器)