java 自动加载配置文

java 自动加载配置文件 org.apache.commons.configuration包 

应用中一些属性来自配置文件,例如access-config.properties。此文件经常需要更新,但希望不用重启服务器。 

private static PropertiesConfiguration configs = null;

static {
   try {
    configs = new PropertiesConfiguration(SPServiceUtil.class
      .getResource("/access-config.properties"));
    configs.setReloadingStrategy(new FileChangedReloadingStrategy());
      } catch (ConfigurationException ex) {
    ex.printStackTrace();
   }
}

如此,代码中再引用configs就不需要再重启服务器而直接生效了。

posted @ 2012-05-15 21:59  王新的博客  阅读(425)  评论(0编辑  收藏  举报