在运行时更新属性文件 [英] update properties file at runtime

查看:83
本文介绍了在运行时更新属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring的项目(例如A).项目A在内部依赖于其他项目(说B)执行少量任务.因此,可以在A Project的server.properties文件中配置B Project URL.

因此,现在每次B项目的URL更改时,我都必须关闭A项目,更改server.properties文件中的URL,然后再次启动服务器.

因此,我有要求用户使用GUI输入新URL并在运行时更改URL的要求.

我知道可以在运行时更改属性的值,但是将仅为该会话设置属性值,而不是对属性文件进行实际修改,并且一旦服务器重新启动,它将引用旧的URL,因为实际更改显示在会话中,而不是实际的属性文件.

我的实际需求是更改应该反映在属性文件中(以便将来重新启动服务器,它应该可以工作)以及bean配置文件中(对于当前会话-我知道该怎么做.)

现在我的要求是,每当配置发生任何更改时,它也应该物​​理上更改属性文件...是否有任何整洁的方法来执行此操作,而不是读取File并搜索该键,然后替换子字符串.

是否有任何第三方api可以很好地做到这一点.

解决方案

您可以在运行时使用示例更新和读取属性

希望获得帮助!

I have one Project (say A) which uses Spring. Project A internally depends on other project (Say B) for few Task. So B Project URL is configurable in server.properties file of A Project.

So now each time URL for B project get changed then I have to shutdown A Project, change the URL in server.properties file and then again start the server.

So I have requirement as to ask user to enter the new URL using GUI and change the URL at runtime.

I know it is possible to change the value of the property at runtime but it will be set only for that session and not an actual modification to properties file, and once the server is restarted again it will refer to old URL because actual changes are present in Session and not to actual Properties file.

my actual need is that changes should be reflected in properties file(for future restart of server it should work) as well as in beans configuration File(for current session - I am aware of how to do.)

Now my requirement is, whenever any changes comes in configuration then it should also physically change the properties file...is there any neat way to do this instead of reading File and search for that key and then replace substring.

Is there any third party api to do this nicely.

解决方案

You can update properties file at runtime by using Commons Configuration API then get value by key. Here is good working example update and read properties

Hope this help!

这篇关于在运行时更新属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆