我正在使用apache camel,我将需要jndi注册表,以便我可以将对象绑定到它。
如何从RouteBuilder类中检索JNDI注册表?我还可以使用xml绑定吗? 谢谢!
答案 0 :(得分:4)
我能够在RouteBuilder中但在向camelMain
添加上下文之前完成。
JndiRegistry registry = new JndiRegistry();
...
registry.bind("myAntFilter", filter);
DefaultCamelContext context = new DefaultCamelContext(registry);
camelMain.getCamelContexts().add(context);
同样重要的是要注意,您需要在/ resources中使用以下内容的jndi.properties:
java.naming.factory.initial = org.apache.camel.util.jndi.CamelInitialContextFactory
没有这个,我得到了例外。
希望能帮助那些偶然发现同样问题的人
答案 1 :(得分: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();
否则,您可以通过blueprint.xml
或META-INF.spring
中的弹簧上下文文件将内容(bean,服务引用等)绑定到注册表中。
出于测试目的,您有CamelTestSupport.createRegistry()
。