2014-03-31 118 views
2

有誰知道是否有機會直接在駱駝處理器中讀取.cfg文件?駱駝處理器和.cfg文件

我.cfg的樣子: 鍵=值 鍵=值 ...

而且我想它的鍵之後,得到一個特定的值,但我想這樣做,在一個處理器!

謝謝!

+0

您需要創建處理器才能使用它。您可以在通過構造函數實例化處理器時將其傳入。 – hveiga

回答

0

只需使用普通的舊式Java:

Reader reader = new FileReader("myprop.cfg"); 
Properties prop = new Properties(); 
prop.load(reader); 

也看看Read contents of a file containing key value pairs without normal parsing。正如克勞斯易卜生所說的,在未來的駱駝版本中,很有可能會添加一個File - >Properties轉換器,請參閱https://issues.apache.org/jira/browse/CAMEL-7312

如果你只需要訪問某些鍵值對,使用駱駝的屬性組成:

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"> 
    <property name="location" value="classpath:com/mycompany/myprop.cfg"/> 
</bean> 

訪問你的路由屬性與{{key}}語法:

<to uri="{{cool.end}}"/> 

Camel documentation顯示所有的可能性。