camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <willem.ji...@gmail.com>
Subject Re: Spring doesn't inject a ProducerTemplate
Date Sun, 28 Oct 2012 04:52:48 GMT
I did some test with common Spring application context, the injection works out of box.
Not sure if it is relates to the Spring MVC. 
Can I know which version of Spring are you using?

I think you can work around it by looking up the CamelContext from the Spring ApplicationContext
which is passed to your SearchController. Then you can create a template as you want. 

-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Sunday, October 28, 2012 at 8:19 AM, scottj wrote:

> hello,
> I read the article on POJO-producing
> (http://camel.apache.org/pojo-producing.html) and thought this would be a
> neat way of sending POJOs from my Spring MVC webapp to a Camel route. But I
> can't seem to get Spring to inject the ProducerTemplate in my Spring MVC
> Controller. The producer in the example below is null. Any suggestions would
> be highly appreciated!
> 
> applicationContext.xml
> <import resource="camel-context.xml"/>
> <bean id="searchController" class="com.acme.controller.SearchController"/>
> 
> camel-context:
> <context:annotation-config/>
> <context:component-scan base-package="com.acme.routes" />
> <camelContext xmlns="http://camel.apache.org/schema/spring"
> id="routerCamelContext">
> <routeBuilder id="searchRouter" ref="searchRouter" />
> </camelContext>
> 
> SearchRouter.java
> from("direct:foo").log(LoggingLevel.INFO, "incoming :
> ${body}").to("direct:bar");
> 
> SearchController.java
> @EndpointInject(uri = "direct:foo")
> ProducerTemplate producer;
> ...
> producer.sendBody(request);
> 
> 
> The log says:
> [main] INFO org.apache.camel.spring.SpringCamelContext - Apache Camel 2.10.2
> (CamelContext: routerCamelContext) is starting
> [main] INFO org.apache.camel.spring.SpringCamelContext - Route: route1
> started and consuming from: Endpoint[direct://foo]
> [main] INFO org.apache.camel.spring.SpringCamelContext - Total 1 routes, of
> which 1 is started.
> [main] INFO org.apache.camel.spring.SpringCamelContext - Apache Camel 2.10.2
> (CamelContext: routerCamelContext) started in 0.319 seconds
> 
> but it all ends up in an NPE...
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Spring-doesn-t-inject-a-ProducerTemplate-tp5721657.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Mime
View raw message