camel - get jndi registry

和自甴很熟 提交于 2019-12-08 07:41:10

问题


I'm using apache camel, and I will be needing the jndi registry so that I can bind an object to it.

How do I retrieve a JNDI registry from a RouteBuilder class? Can I also bind using xml? Thanks!


回答1:


I was able to do it not within the RouteBuilder but before adding context to the camelMain.

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

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

It is also important to note that you need to have a jndi.properties in your /resources with the following content:

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

Without this, I'm getting an exception.

Hope it helps people who stumbled on the same problem




回答2:


Does CamelContext.getRegistry() suit your needs?

/**
 * 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();

Otherwise, you can bind things (beans, service references, etc) into the registry via blueprint.xml or the spring context files located in META-INF.spring.

For testing purposes, you have CamelTestSupport.createRegistry().



来源:https://stackoverflow.com/questions/21773330/camel-get-jndi-registry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!