12
我有一个主要的conf文件,我使用apache常用配置类加载。 我有一个要求,用户可以指定一个conf文件,这些文件中的值将覆盖主conf中的值。如何使用apache常用配置加载多个配置文件(java)
请建议我们如何在apache常用配置类或任何其他开放源代码类中实现此目的。
在此先感谢
我有一个主要的conf文件,我使用apache常用配置类加载。 我有一个要求,用户可以指定一个conf文件,这些文件中的值将覆盖主conf中的值。如何使用apache常用配置加载多个配置文件(java)
请建议我们如何在apache常用配置类或任何其他开放源代码类中实现此目的。
在此先感谢
我想你想类似的东西the mechanism described here:
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new PropertiesConfiguration("user.properties"));
config.addConfiguration(
new PropertiesConfiguration("application.properties"));
// user preferences have precedence over application preferences
参考:
用cfg4j:
// Specify which files to load. Configuration from both files will be merged.
ConfigFilesProvider configFilesProvider =() -> Arrays.asList(new File("application.properties"), new File("otherConfig.properties"));
// Use local files as configuration store
ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);
然后以标准方式使用它来获得属性。
我创建了一个文件“loader.properties”,它有两行,include = a.properties和include = b.properties。它仍然包含a.properties,但不包含b.properties。我使用PropertyConfiguration来加载“loader.properties”文件。你知道为什么吗? – Sujoy 2015-03-17 17:09:37