Beans not found in registry when Camel load routes from XML file

Viewed 4214

I have a issue in camel, loading routes from XML at run time. I searched for my problem and found related discussion at : http://grokbase.com/p/camel/users/117w8m6rbm/injecting-data-to-routes-loaded-from-xml-file.

My issue is little bit differen. i want to run that route which is given below.

<routes xmlns="http://camel.apache.org/schema/spring">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd" >
<bean id="myDb" class="com.mongodb.MongoClient">
<constructor-arg name="host" value="localhost" />
    <constructor-arg name="port" value="27017" />
</bean>
<bean id="mongodb" class="org.apache.camel.component.mongodb.MongoDbComponent"></bean>
</beans>
<route id="_route1">
        <description>here is a sample which subscribe data( proper json object) from mqtt topic  from broker and push into Mongo Db</description>
        <from id="_from1" uri="paho:iot/test/#?brokerUrl=tcp://localhost:1883"/>
        <to id="_to2" uri="mongodb:myDb?database=Volt&amp;collection=dummyData&amp;operation=insert"/>
</route>
</routes>

it gives me exception :

14:14:58.249 INFO  c.v.integration.route.CustomRouter - Exception {}
org.apache.camel.FailedToCreateRouteException: Failed to create route _route1: Route(_route1)[[From[paho:iot/test/#?brokerUrl=tcp://localho... because of No bean could be found in the registry for: myDb of type: com.mongodb.MongoClient
    at org.apache.camel.impl.RouteService.warmUp(RouteService.java:143) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3619) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3526) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3312) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3166) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:183) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2961) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2957) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2980) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2957) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2924) ~[camel-core-2.18.3.jar:2.18.3]
    at com.volt.integration.route.CustomRouter.process(CustomRouter.java:36) ~[classes/:na]
    at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:120) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:460) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:227) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:191) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102) [camel-core-2.18.3.jar:2.18.3]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_121]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: myDb of type: com.mongodb.MongoClient
    at org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:159) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.component.mongodb.MongoDbEndpoint.doStart(MongoDbEndpoint.java:288) ~[camel-mongodb-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:236) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:60) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:90) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:80) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:60) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:90) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.RedeliveryErrorHandler.doStart(RedeliveryErrorHandler.java:1448) [camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:44) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ChildServiceSupport.start(ChildServiceSupport.java:31) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:60) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:90) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.interceptor.DefaultChannel.doStart(DefaultChannel.java:156) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:60) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:90) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.processor.DelegateAsyncProcessor.doStart(DelegateAsyncProcessor.java:80) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:75) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.RouteService.startChildService(RouteService.java:348) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.RouteService.doWarmUp(RouteService.java:191) ~[camel-core-2.18.3.jar:2.18.3]
    at org.apache.camel.impl.RouteService.warmUp(RouteService.java:141) ~[camel-core-2.18.3.jar:2.18.3]
    ... 31 common frames omitted

how can i put the bean in registry at run time ? or how can i referencing the bean which is required for mongodb(client) ? or is there other way to run this route ? i am unable to run this route at run time. kindly suggest me a solution. thanks in Advance .

2 Answers
Related