管理配置数据的最佳方法是什么 [英] What is the best way to manage configuration data

查看:119
本文介绍了管理配置数据的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款包含4种产品的产品套件。现在,所有配置数据都在XML或属性文件中。这种方法不可维护,因为我们必须为不同的环境管理不同的配置文件(例如生产,开发等)。

I am working on a product suite which has 4 products. Right now, all of the configuration data is either in the XML or properties files.This approach is not maintainable as we have to manage different configuration file for different environment(for e.g. Production, Development etc).

那么,处理配置数据的最佳方式是什么?

另外,我们可以将其模块化为单独的模块?这样所有产品都可以使用这个模块。
我们不想使用属性文件。我正在寻找一种解决方案,我们可以将所有配置特定代码作为新的配置模块移动,并将所有配置数据保存在数据库中。

Also, can we modularize this into a separate module? So that all products can use this module. We don't want to use the property files. I am looking for a solution in which we can move all of the configuration specific code as a new configuration module and persist all the configuration data in database.

推荐答案

使用 commons-configuration ,您可以使用统一的API来访问属性,无论它们如何表示 - .properties,xml,JNDI等。例如:

Using commons-configuration you have a unified API for accessing the properties, no matter how they are represented - .properties, xml, JNDI, etc. For example:

config.properties

jdbcHost=192.168.12.35
jdbcUsername=dbuser
jdbcPassword=pass

config.xml

<config>
   <jdbcHost>192.168.12.35</jdbcHost>
   <jdbcUsername>dbuser</jdbcUsername>
   <jdbcPassword>pass</jdbcPassword>
</config>

在这两种情况下都可以通过以下方式访问:

in both cases they will be accessible with something like:

String host = config.getString("jdbcHost");

这篇关于管理配置数据的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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