You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by mumbly <mc...@gmail.com> on 2009/12/01 16:53:43 UTC

Re: Using Guice with Camel

So I managed to get rid of the error message. I'm not sure if it is possible
to make the error message more informative. For example, in a very similar
situation, I had an error message when I had a route builder with jms, when
I didn't have camel-jms loaded and I got:

1) Failed to resolve endpoint: jms://test.MyQueue due to: No component found
with scheme: jms
  while locating org.apache.camel.guice.GuiceCamelContext
  while locating org.apache.camel.CamelContext

Anyway, just a minor point.

I do have a couple of general questions in trying to understand things.

So is .beanRef() a Guice specific method or is it used for Spring, also? Or
is it simply built for using JNDI and it is just the fact that Guice acts as
a JNDI store backed by Guice beans?

And what is the thinking behind Guice JNDI? Is it just there to allow for a
simple way for retrieving beans that have been initialized by Guice without
carrying around the injector? I see that it is used to inject values that
have been defined in jndi.properties, but is it more generally usable to get
any and all Guice enhanced beans as long as they have been annotated? Do I
need to do anything other than annotate the bean? Will it serve to fully
build up the bean graph of all components associated with the bean annotated
with JMS?

--Tim


willem.jiang wrote:
> 
> Hi,
> 
>   camel-guice has a jndi context which hold the reference of the JMS 
> component and the someBean. So you need to create that context in your 
> GuceServletConfig.
> 
> You can find use code in the MyActivitor[1] about how to create that 
> context.
> 
> [1] 
> https://svn.apache.org/repos/asf/camel/trunk/examples/camel-example-guice-jms/src/main/java/org/apache/camel/example/guice/jms/MyActivator.java
> 
> Willem
> mumbly wrote:
>> Thanks for all the help so far. You're example worked great.
>> 
>> I'm running into an error when integrating the camel routes into a webapp
>> where I use the guice servlet for initialization. I have the same set of
>> changes you included in your diff, but the startup happens from a
>> listener
>> defined in web.xml and looking like:
>> 
>> public class GuiceServletConfig extends GuiceServletContextListener {
>>     protected Injector getInjector() {
>>         Module camel = new MyModule();
>>         return Guice.createInjector(camel);
>>     }
>> 
>> there is some other code in there, but I've tried it with this simple
>> version. When I run, the error I get is:
>> 
>> com.google.inject.CreationException: Guice creation errors:
>> 
>>   while locating org.apache.camel.guice.GuiceCamelContext
>>   while locating org.apache.camel.CamelContext
>> 
>> 1 error
>> 	at
>> com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354)
>> 	at
>> com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:179)
>> 	at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113)
>> 	at com.google.inject.Guice.createInjector(Guice.java:92)
>> 	.
>> 
>> Any thoughts on this? I've confirmed that both the camel-guice and
>> camel-core jars are in the WEB-INF/lib.
>> 
>> --Tim
>>  
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Using-Guice-with-Camel-tp26517323p26594078.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Using Guice with Camel

Posted by Willem Jiang <wi...@gmail.com>.
mumbly wrote:
> So I managed to get rid of the error message. I'm not sure if it is possible
> to make the error message more informative. For example, in a very similar
> situation, I had an error message when I had a route builder with jms, when
> I didn't have camel-jms loaded and I got:
> 
> 1) Failed to resolve endpoint: jms://test.MyQueue due to: No component found
> with scheme: jms
>   while locating org.apache.camel.guice.GuiceCamelContext
>   while locating org.apache.camel.CamelContext
> 
> Anyway, just a minor point.
Camel supports to find the component automatically, you need to make 
sure the camel-jms.jar is in your class patch before loading the camel 
context.

> 
> I do have a couple of general questions in trying to understand things.
> 
> So is .beanRef() a Guice specific method or is it used for Spring, also? Or
> is it simply built for using JNDI and it is just the fact that Guice acts as
> a JNDI store backed by Guice beans?
.beanRef() is a DSL which let you to find the bean instance from the 
camel registry. This registry can be a spring application context or a 
jndi context.
In your case, we create a @Provider method which creates a bean instance 
from Guice injector and register it with @JndiBind annotation into the 
Camel Guice jndi.

> 
> And what is the thinking behind Guice JNDI? Is it just there to allow for a
> simple way for retrieving beans that have been initialized by Guice without
> carrying around the injector? 
You can treat Guice JNDI as another registry that can be used by camel 
context. You can register not only bean instance , but also the 
processor, components , etc.
These objects can be initialized by Guice injector or not.

>I see that it is used to inject values that
> have been defined in jndi.properties, but is it more generally usable to get
> any and all Guice enhanced beans as long as they have been annotated? 
Current jndi.properties name is bind with the injector, I don't think it 
can help you to get the Guice enhanced beans there,

> Do I
> need to do anything other than annotate the bean? Will it serve to fully
> build up the bean graph of all components associated with the bean annotated
> with JMS?
You can get the @Inject annotated beans from the Guice Injector.
If you want the bean to be put into the camel context registry, you need 
add the @JndiBind anntotation.
> 
> --Tim
> 
> 


Willem