问题
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