camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Using Guice with Camel
Date Fri, 27 Nov 2009 08:21:55 GMT
On Thu, Nov 26, 2009 at 6:27 PM, mumbly <> wrote:
> So to make things simple, let's base it on the existing Guice/Camel example.
> So in, let's say I want to include an injected component and
> add:
> public class SomeBean {
>  @Inject
>  private OtherBean ob;
>  public void someMethod(String body) {
>     System.out.println("Received: " + body);
>     System.out.println("OtherBean: " + ob);
>  }
> Define OtherBean as you wish. I'd expect(hope) without any other
> configuration that I'd get a non-null result for OtherBean, just using
> default binding values. It seems that it should be able to autowire (or
> whatever the Guicey version of that term is) ob. But though the
> configuration seems to be done via Guice, I don't think once "inside the
> routing context" that Guice is used to build/instantiate the bean from:
> from("file://target/routeOutput?noop=true").
>                bean(new SomeBean());
> I can see that it seems to have been created by new and not via Guice. What
> I'm wondering is if there is some way that I can tell it to grab a via built
> up via Guice instead of passing a specific instance.

The fluent builder is *just* regular Java code. So instead of bean(new
SomeBean()); you should be able to refer to a object which Guice have

@Inject (or whatever the Guice notion is)
private SomeBean some;

from ....

> Does that make sense? As I mentioned, I'm still new with both Guice and
> Camel, so I could be way off the mark here.
> --Tim
> willem.jiang wrote:
>> What kind of Object you want to inject into the bean component?
>> Did you add that bind in your module ?
>> Please let me have a look at your module class.
>> Willem
>> mumbly wrote:
>>> I've been taking a look at using Camel with Guice for DI, but I'm having
>>> a
>>> little trouble understanding exactly what the integration provides. I've
>>> got
>>> the configuration aspect and that seems to work fine. But it is unclear
>>> to
>>> me if/how to work with Guice enhanced components. Specifically, if I am
>>> using a bean component which uses @Inject, it doesn't appear that the
>>> bean
>>> is being pulled from the Guice context (in other words, the other
>>> components
>>> aren't being injected).
>>> I'm new to both Camel and Guice, so I could be missing something obvious
>>> here or there may be another pattern for DI using Guice with Camel that I
>>> missed. So I guess my basic question is does the Camel/Guice integration
>>> provide the ability to inject components within the routing chain? with
>>> the
>>> bean component?
>>> I see in the Guice example included in the dist, but it only seems to
>>> deal
>>> with using Guice for configuration of the routes.
>>> --Tim
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at

Claus Ibsen
Apache Camel Committer

Author of Camel in Action:
Open Source Integration:

View raw message