问题描述
我正在清除 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.它比 xml 简单得多,更易于使用,而且实现起来微不足道.
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,并且您从磁盘存储或检索的数据被建模为键值对(在您的情况下听起来就像是这样),那么我真的想不出更好的解决方案.
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 配置框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!