2017-04-05 212 views
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實現的接口,但我對我如何使用的細節模糊兩種不同的類型使我的程序運行。

回答

0

問題出在我的導入聲明中。我有:

import org.apache.commons.configuration.Configuration; 
import org.apache.commons.configuration2.PropertiesConfiguration; 

所以我從兩個不同的來源進口,因此爲什麼類型不兼容。