2014-02-14 38 views
1

我使用apache駱駝,我將需要jndi註冊表,以便我可以將一個對象綁定到它。駱駝 - 獲取jndi註冊表

如何從RouteBuilder類中檢索JNDI註冊表?我可以使用xml綁定嗎? 謝謝!

+0

這是用於實時代碼還是測試代碼?因爲在'CamelTestSupport'派生的測試中你有'CamelTestSupport.createRegistry()' – vikingsteve

回答

3

我能夠做到這一點不是在RouteBuilder內部,而是在向camelMain添加上下文之前。

JndiRegistry registry = new JndiRegistry(); 
... 
registry.bind("myAntFilter", filter); 

DefaultCamelContext context = new DefaultCamelContext(registry); 
camelMain.getCamelContexts().add(context); 

同樣重要的是要注意,你需要在你的/資源jndi.properties具有以下內容:

java.naming.factory.initial的= org.apache.camel.util .jndi.CamelInitialContextFactory

沒有這個,我得到一個異常。

希望它可以幫助那些偶然發現同樣問題的人

+0

謝謝@ yin03。 這非常有幫助。 –

0

請問CamelContext.getRegistry()是否符合您的需求?

/** 
* Returns the registry used to lookup components by name and type such as the Spring ApplicationContext, 
* JNDI or the OSGi Service Registry 
* 
* @return the registry 
*/ 
Registry getRegistry(); 

否則,您可以通過位於META-INF.springblueprint.xml或Spring上下文文件綁定的東西(豆類,服務引用等)到註冊表中。

出於測試目的,您有CamelTestSupport.createRegistry()