【问题标题】:Commons - Configuration CompositeConfiguration and PreferencesCommons - 配置 CompositeConfiguration 和 Preferences
【发布时间】:2011-04-01 09:01:55
【问题描述】:

我正在使用 CompositeConfiguration 从多个来源(如 .propeties 文件、xml 文件、系统属性等)读取属性,如下所示。

ConfigurationFactory factory = new ConfigurationFactory("config.xml");
compConfig = (CompositeConfiguration)factory.getConfiguration();
compConfig.getProperty(propName);

配置.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<properties fileName="Properties1.properties"/>
<properties fileName="Properties2.properties"/>
<properties fileName="Properties3.properties"/>
<system/>
</configuration>

除了这些文件,我还想阅读保存在 Windows 注册表中的首选项。我了解 java.util.Preferences API 可用于访问 Windows 注册表中的值。我只是想知道是否有办法使用 PropertiesConfiguration 来读取它们?

谢谢

【问题讨论】:

    标签: java apache-commons-config


    【解决方案1】:

    看起来您需要提供自己的 AbstractConfiguration 类实现。如果您愿意为JNDI provider for the windows registry 付费,也可以使用JNDIConfiguration 课程

    【讨论】:

    猜你喜欢
    • 2018-09-26
    • 2014-11-08
    • 1970-01-01
    • 1970-01-01
    • 2019-01-29
    • 2013-02-26
    • 2012-01-28
    • 2011-06-26
    • 2018-07-25
    相关资源
    最近更新 更多