0
我在Apache Commons Configuration中配置和PropertiesConfiguration類型有一些概念上的困難。配置與屬性配置
PropertiesConfiguration config = createConfig();
BlazeGraphEmbedded graph = BlazeGraphEmbedded.open(repo, config);
createConfig()方法:
public static PropertiesConfiguration createConfig()
{
PropertiesConfiguration config = null;
Parameters params = new Parameters();
BasicConfigurationBuilder<PropertiesConfiguration> builder =
new BasicConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
.configure(params.basic()
.setListDelimiterHandler(new DefaultListDelimiterHandler(','))
.setThrowExceptionOnMissing(true));
try {
config = builder.getConfiguration();
config.addProperty("VALUE_FACTORY", BVF_extendo4000.INSTANCE);
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Returning config.");
return config;
}
我想創建一個配置對象傳遞給在BlazeGraphEmbedded類open方法。但是,我的createConfig方法返回一個PropertiesConfiguration對象,BlazeGraphEmbedded.open(Repository,Configuration)方法不會接受該對象。我沒能到我的PropertiesConfiguration投來配置,它產生一個運行時錯誤:
Exception in thread "main" java.lang.ClassCastException:
org.apache.commons.configuration2.PropertiesConfiguration cannot be cast to
org.apache.commons.configuration.Configuration
據我所知,配置是由PropertiesConfiguration實現的接口,但我對我如何使用的細節模糊兩種不同的類型使我的程序運行。