Hi , You need to use the SimpleRegistry to hold the reference of HelloBean and pass it to the DefaultCamelContext just like this
SimpleRegistry registry = new SimpleRegistry(); registry.put(“HelloBean”, new HelloBean); CamelContext context = new DefaultCamelContext(registry); -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Wednesday, November 13, 2013 at 1:24 PM, Manoranjitham G wrote: > Hi, > > I am trying to invoke a method in a bean but it is showing the error message > *No bean could be found in the registry for: HelloBean* > > > here is my beanclass: > public class *HelloBean* { > public String hello(){ > > return "name=Tom"; > } > > } > > camel class: > > import org.apache.camel.CamelContext; > import org.apache.camel.builder.RouteBuilder; > import org.apache.camel.impl.DefaultCamelContext; > import org.apache.camel.impl.SimpleRegistry; > import org.apache.camel.util.jndi.JndiContext; > > public class CamelScenario_2 > { > > public static void main(String args[]) > { > CamelContext context=new DefaultCamelContext(); > > try > { > context.addRoutes(new RouteBuilder() { > public void configure() { > System.out.println("---------------"); > from("direct:start").beanRef("HelloBean") > > .process(new Processor() { > > > @Override > public void process(Exchange exchange) throws Exception > { > String name = exchange.getIn().getBody(String.class); > log.info (http://log.info)("-------------->Initial name is " + > exchange.getIn().getBody(String.class)); > HelloBean hello = new HelloBean(); > String answer = hello.hello(); > exchange.getOut().setBody(answer); > System.out.println("The name is " + > exchange.getOut().getBody(String.class)); > > } > }).to("file://test"); > > } > > }); > } > catch(Exception exception) > { > exception.printStackTrace(); > } > > try > { > context.start(); > while(true) > { > > } > } > catch(Exception exception1) > { > > exception1.printStackTrace(); > } > } > } > > > > Error Message: > 10:35:13.893 [main] INFO o.a.camel.impl.DefaultCamelContext - Apache Camel > 2.11.1 (CamelContext: camel-1) uptime 0.481 seconds > 10:35:13.893 [main] INFO o.a.camel.impl.DefaultCamelContext - Apache Camel > 2.11.1 (CamelContext: camel-1) is shutdown in 0.010 seconds > org.apache.camel.FailedToCreateRouteException: Failed to create route route1 > at: >>> Bean[ref:HelloBean] <<< in route: Route(route1)[[From[direct:start]] > -> [Bean[ref:HelloBean], ... because of No bean could be found in the > registry for: HelloBean > at > org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:883) > at > org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:176) > at > org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:751) > at > org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1845) > at > org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1625) > at > org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1500) > at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) > at > org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1468) > at > com.polaris.mh.camel.poc.scenario_2.CamelScenario_2.main(CamelScenario_2.java:71) > Caused by: org.apache.camel.NoSuchBeanException: *No bean could be found in > the registry for: HelloBean* at > org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:68) > at > org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:196) > at > org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:479) > at > org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:197) > at > org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:880) > ... 8 more > > > Please help me resolve this . > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/bean-Registry-tp5743143.html > Sent from the Camel - Users mailing list archive at Nabble.com > (http://Nabble.com).
