If you use spring xml file, then the registry is by default the spring
app context.

So you can just define your holder bean in the spring xml file

<bean id="HelloBean" class="xxxx.MyHelloBean"/>

And Camel can lookup in spring and find the bean by its id

On Tue, Nov 26, 2013 at 3:55 PM, Singh, Surya Prakash
<ssi...@tiaa-cref.org> wrote:
> How do you achieve this when using spring dsl to create a camelcontext?
>
> <camelContext lazyLoadTypeConverters="true" id="camelContext" 
> xmlns="http://camel.apache.org/schema/spring";>
> </camelContext>
>
> Is there a way to inject a SimpleRegistry when creating a CamelContext in 
> spring DSL? What is the namespace for that?
>
> Regards,
>
>
> -----Original Message-----
> From: Willem jiang [mailto:willem.ji...@gmail.com]
> Sent: Wednesday, November 13, 2013 1:27 AM
> To: users@camel.apache.org
> Subject: Re: bean Registry
>
> 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(DefaultCamelConte
>> xt.java:751)
>> at
>> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(Defaul
>> tCamelContext.java:1845)
>> at
>> org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelCon
>> text.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.ja
>> va: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.j
>> ava:196)
>> at
>> org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefi
>> nition.java:479)
>> at
>> org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefiniti
>> on.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).
>
>
>
>
> *************************************************************************
> This e-mail may contain confidential or privileged information.
> If you are not the intended recipient, please notify the sender immediately 
> and then delete it.
>
> TIAA-CREF
> *************************************************************************



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to