java - 更新 Web 应用程序中的属性文件

标签 java tomcat web-applications properties-file

我有一个属性文件(在 rsources 文件夹下),我在其中存储了一个变量(键=值),

当用户插入新值或更新旧值时,我需要更新它,我可以这样做吗? 我有疑问,因为它是一个 Web 应用程序,所以它只是部署在服务器中的一场 war 。那么如何访问 .properties 文件并直接从代码中更改它呢?

如果不行,是否有其他解决方案?

最佳答案

也许用户可以在文件系统中提供一个覆盖属性文件,其值将覆盖打包的默认属性文件。

查看 Apache Commons Configuration ,这permits this capability .

Often you want to provide a base set of configuration values, but allow the user to easily override them for their specific environment. Well one way is to hard code the default values into your code, and have then provide a property file that overrides this. However, this is a very rigid way of doing things. Instead, with the CompositeConfiguration you can provide many different ways of setting up a configuration.

关于java - 更新 Web 应用程序中的属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950743/

相关文章:

java - 如何恢复平衡服务器上的端口

javascript - 如何检测网站中是否存在鼠标?

php - 错误 : TypeError: document. getElementById ("count2") 为空,因为条件表。怎么修?

java - 如何使用 JAXB 读取 XML 文件?

java - 客户端服务器端通信java

java - Struts2:如何在 webapp 之外存储图像并将其路径保存到数据库?

tomcat - 后台线程 Tomcat Struts2

tomcat - 失败 - 在上下文路径/blah 处部署了应用程序,但上下文无法启动

java - 有没有人有 Apache POI 将 PPTX 转换为 PNG 的示例

java - EhCache key 类型