Ah...I finally figured it out. The bean that wasn't getting injected is in
a spring dispatcher context, NOT the main app context. In other words, I
have:
applicationContext.xml
- this is where the <camelContext> is declared
web.xml:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
dispatcher-servlet.xml:
<context:component-scan base-package="com.mycompany.controller"/>
The "problem object" is com.mycompany.controller.FooController. It gets
autowired no problem by spring...so it has no trouble depending on beans in
applicationContext.xml. But it's NOT getting injected by camel.
I guess I'm not too surprised now that I think about it. But what do you
think? Is there a way to get camel to wire up dependencies in dispatcher
contexts like this?
If not, I suppose I should just create a separate <camelContext> inside
dispatcher-servlet.xml, but that seems like a waste to me, and could
introduce some "interesting" issues down the line...
Otherwise I guess I'll have to push this particular producer into a bean
that lives in applicationContext.xml, not in the controller itself...hm.
Any ideas?
Thanks,
Dan
On Tue, Feb 1, 2011 at 10:38 AM, Claus Ibsen <[email protected]> wrote:
> Thats a bit odd as its just OO. But create a JIRA and attach a small
> unit test, that would be great.
>
>
> On Tue, Feb 1, 2011 at 3:20 PM, Dan Checkoway <[email protected]>
> wrote:
> > Before I report this in JIRA as a bug in Camel 2.6.0, I want to make sure
> > what I'm trying to do is actually supported.
> >
> > When I use @EndpointInject in a bean in my spring app context, the
> endpoint
> > gets injected no problem on either a ProducerTemplate or Endpoint. But
> when
> > I use @EndpointInject on a *SUPERCLASS* of my bean(s), the endpoint does
> NOT
> > get injected and I end up getting a NullPointerException when I try to
> use
> > it.
> >
> > Pseudo-code below...please let me know if what I'm trying to do should be
> > supported. I believe this is a bug in the annotation processor, where
> it's
> > not processing superclasses.
> >
> > // ================= THIS WORKS:
> >
> > @Component
> > public class AllGood {
> > @Autowired
> > ProducerTemplate producerTemplate;
> > @EndpointInject(uri="activemq:queue:my.queue")
> > Endpoint myQueue;
> >
> > public void send() {
> > producerTemplate.sendBody(myQueue, "body");
> > }
> > }
> >
> > // ================= THIS ALSO WORKS:
> >
> > @Component
> > public class AllGood {
> > @EndpointInject(uri="activemq:queue:my.queue")
> > ProducerTemplate producerTemplate;
> >
> > public void send() {
> > producerTemplate.sendBody("body");
> > }
> > }
> >
> > // ================= THIS DOES NOT WORK:
> >
> > public abstract class BaseClass {
> > @Autowired
> > ProducerTemplate producerTemplate;
> > @EndpointInject(uri="activemq:queue:my.queue")
> > Endpoint myQueue;
> >
> > public void send() {
> > producerTemplate.sendBody(myQueue, "body");
> > }
> > }
> >
> > @Component
> > public class SubClass1 extends BaseClass {
> > public void doSomeStuff() {
> > send();
> > }
> > }
> >
> > // ================= NEITHER DOES THIS:
> >
> > public abstract class BaseClass {
> > @EndpointInject(uri="activemq:queue:my.queue")
> > ProducerTemplate producerTemplate;
> >
> > public void send() {
> > producerTemplate.sendBody("body");
> > }
> > }
> >
> > @Component
> > public class SubClass2 extends BaseClass {
> > public void doSomeStuff() {
> > send();
> > }
> > }
> >
> > // =========================
> >
> > Thanks,
> > Dan
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: [email protected]
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>