Java配置框架 [英] Java configuration framework
问题描述
我正在排除Java库中的所有硬编码值,并且想知道什么框架是最好的(就零或接近零配置而言)来处理运行时配置?我喜欢基于XML的配置文件,但它不是必需的。
I'm in the process of weeding out all hardcoded values in a Java library and was wondering what framework would be the best (in terms of zero- or close-to-zero configuration) to handle run-time configuration? I would prefer XML-based configuration files, but it's not essential.
如果您对框架有实际经验,请只回复。我不是在寻找例子,但经验...
Please do only reply if you have practical experience with a framework. I'm not looking for examples, but experience...
推荐答案
如果你的硬编码值只是简单的键值对,您应该查看 java.util.Properties 。
If your hardcoded values are just simple key-value pairs, you should look at java.util.Properties. It's a lot simpler than xml, easier to use, and mind-numbingly trivial to implement.
如果你正在使用Java和你正在存储或从磁盘检索的数据,那么它会比xml更简单,更容易使用,被建模为一个键值对(它听起来像是在你的情况下),然后我真的不能想象一个更好的解决方案。
If you are working with Java and the data you are storing or retrieving from disk is modeled as a key value pair (which it sounds like it is in your case), then I really can't imagine a better solution.
我使用属性文件对于一个更大的项目中的小包的简单配置,以及作为整个项目的更全局的配置,我从来没有遇到过问题。
I have used properties files for simple configuration of small packages in a bigger project, and as a more global configuration for a whole project, and I have never had problems with it.
不需要任何第三方库利用的巨大好处。
Of course this has the huge benefit of not requiring any 3rd party libraries to utilize.
这篇关于Java配置框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!