公司一个项目的从另外一个小公司,拷贝了一个PropertyParser的类,实现的有问题,必须重启java应用才能读取新的配置。

简单的解决办法,就是每次读任何配置项时,都重新加载xxx.property文件,但是明显不如当年C#的ConfigurationManager好用。

https://stackoverflow.com/questions/20661612/java-equivalent-for-cs-configurationmanager-appsettingsx

这篇文章,只回答了web的,没有针对desktop和console类型的解答。

http://blog.163.com/s_zhchluo/blog/static/15014708200732191454527/

这篇文章提到了 Apache Commons Configuration项目,也解释了其功能原理,很符合我的要求。

https://commons.apache.org/proper/commons-configuration/

The Commons Configuration software library provides a generic configuration interface which enables a Java application to read configuration data from a variety of sources. 

望文生义,就是通用的配置库,很不错。

http://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_filebased.html

节选Automatic Reloading部分的说明:

Automatic Reloading

A common issue with file-based configurations is to handle the reloading of the data file when it changes. This is especially important if you have long running applications and do not want to restart them when a configuration file was updated. Commons Configuration has the concept of so called reloading strategies that can be associated with a file-based configuration. Such a strategy monitors a configuration file and is able to detect changes. A default reloading strategy is FileChangedReloadingStrategy. It can be set on a file-based configuration as follows:

PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setReloadingStrategy(new FileChangedReloadingStrategy());

FileChangedReloadingStrategy works as follows: On every property access the configuration checks its associated reloading strategy. FileChangedReloadingStrategy will then obtain the last modification date of the configuration file and check whether it has changed since the last access. If this is the case, a reload is triggered. To avoid often disk access when multiple properties are queried from the configuration, a refresh delay can be set on the reloading strategy. This is a time in milli seconds with the meaning that the reloading strategy will only once check the file's last modification time in the period specified here.

每一次属性访问时,都会检查文件,如果最后访问时间有变化,则自动重新载入。为了减少硬盘访问频率,又添加了"刷新延迟(设定刷新延迟时间)"机制。上述机制基于commons-configuration/userguide_v1.10。

还有一篇介绍如何实现重载机制的文章,讲解了其他重载机制。

https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html

Java Configuration Manager Automatic Reloading的更多相关文章

  1. Oracle's Business Intelligence Applications Configuration Manager 基本概念

    Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installatio ...

  2. Spring Security(十二):5. Java Configuration

    General support for Java Configuration was added to Spring Framework in Spring 3.1. Since Spring Sec ...

  3. Windows 8上使用SQL 2012 Configuration Manager

    现在使用Windows 8 + Sql Server 2012,而今天想用SQL 2012 Configuraton Manager, 设置别名来访问不同的开发数据库.但发现没能找到SQL 2012 ...

  4. SQL Server Configuration Manager出错

    在 Windows 桌面上,单击“开始”,然后单击“运行”.  在“打开”框中,键入 MMC,然后单击“确定”.  在“控制台”窗口中,单击菜单栏上的“文件”,然后单击“添加/删除管理单元”.  在“ ...

  5. Sql Server Configuration Manager 网络配置为空,没有实例

    新用户一天内不准提问...Sql Server Configuration Manager 网络配置为空,没有实例无法设置ip和端口进行连接..

  6. Configuration Manager 和内容位置(包源文件)

    Configuration Manager 2007 中的内容位置涉及 Configuration Manager 2007 客户端如何查找播发和软件更新的包源文件.当客户端需要查找内容时,它会将内容 ...

  7. Mybatis Spring multiple databases Java configuration

    https://stackoverflow.com/questions/18201075/mybatis-spring-multiple-databases-java-configuration ** ...

  8. SQL SERVER – Configuration Manager – Cannot Connect to WMI Provider. You Do Not Have Permission or The Server is Unreachable

    打开SQL SERVER Configuarion Manger 出现以下错误 SQL Server Configuration Manager—————————Cannot connect to W ...

  9. System Center Configuration Manager 2016 配置安装篇(Part3)

    SCCM 2016 配置管理系列(Part 1- 4) 介绍AD01上配置了Active Directory域服务(ADDS),然后将Configuration Manager服务器(CM16)加入到 ...

随机推荐

  1. 自己定义控件-DragButton

    版权声明:本文为博主原创文章.欢迎转载,转载请注明博主和原文链接. https://blog.csdn.net/u014077888/article/details/28097273 一.描写叙述 可 ...

  2. 转://点评Oracle11g新特性之动态变量窥视

    1. 11g之前的绑定变量窥视 我们都知道,为了可以让SQL语句共享运行计划,oracle始终都是强调在进行应用系统的设计时,必须使用绑定变量,也就是用一个变量来取代原来出如今SQL语句里的字面值.比 ...

  3. EXCEL 偶数、奇数行分开求和公式

    例举 : A1行是 123 A2行是 321 A3行是 456 A4行是 789我是加的是A1+A3得出的和还有加的是A2+A4得出的和因为要A1+A3一直加到A601,我用很笨的方式像这样子一个个加 ...

  4. M100 对频

  5. 最简单例子图解JVM内存分配和回收(转)

    本文转自http://ifeve.com/a-simple-example-demo-jvm-allocation-and-gc/ http://www.idouba.net/a-simple-exa ...

  6. git fork之如何同步更新

    1.打开git fork的开源项目(这里我以git fork vscode为例): 2.点击New pull request 3.选择你自己的 4.选择完后出现如图 5.调整状态,右边改为源fork地 ...

  7. 类似Visual Studio一样,使用Qt Creator管理多个项目,创建子项目

    1. 简介 QtCreator是一个十分好用的跨平台IDE,由于最近需要在Windows和Mac同时写一个C++的代码,使用VS和XCode不能实现项目的统一管理(可以使用cmake来组织源码,但是每 ...

  8. flask seesion组件

    一.简介     flask中session组件可分为内置的session组件还有第三方flask-session组件,内置的session组件功能单一,而第三方的flask-sessoin可支持re ...

  9. ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-WebApi与Unity注入

    系列目录 前言: 有时候我们系统需要开放数据给手机App端或其他移动设备,不得不说Asp.net WebApi是目前首选 本节记录Asp.net MVC WebApi怎么利用Unity注入.系列开头已 ...

  10. Haproxy基础知识 -运维小结

    开源软件负载均衡器 现在常用的三大开源软件负载均衡器分别是Nginx.LVS.Haproxy. 在之前的文章中已经对比了这三个负载均衡软件, 下面根据自己的理解和使用经验, 再简单说下这三个负载均衡软 ...