Guice cannot detect annotations on local variables this way (although it's an interesting idea!). You have two options here:
1) Make the variable on the class wherever this code is in and add an extra module that has requestInjection(YourClass.this) in its configure method. Then Guice will inject that variable as part of its Injector creation. 2) Use injector.getInstance(Key.get(IDrawGraphService.class, ToDot.class)) instead. That tells Guice that you want to retrieve the instance defined by the Key "@ToDot IDrawGraphService", as opposed to just "IDrawGraphService". sam On Mon, Jul 19, 2010 at 11:21 AM, Jerem's <[email protected]> wrote: > Hello I try to use annotatoij on a local variable : > > this is my module : > > public class DrawModule extends AbstractModule { > > @Override > protected void configure() { > > > this.bind(IDrawGraphService.class).annotatedWith(ToDot.class).to(DrawDotServiceImpl.class); > } > } > > and my Annotation look like that : > > @Retention(RUNTIME) > @Target({ LOCAL_VARIABLE, FIELD, PARAMETER }) > @BindingAnnotation > public @interface ToDot { > > } > > and I try to do that : > > Injector drawGraphInjector = Guice.createInjector(new DrawModule()); > @ToDot > IDrawGraphService drawDotService = > drawGraphInjector.getInstance(IDrawGraphService.class); > > > But I have an exception : > > Exception in thread "main" com.google.inject.ConfigurationException: > Guice configuration errors: > > 1) No implementation for > fr.irisa.cairn.simpleGraph.drawGraph.service.IDrawGraphService was > bound. > while locating > fr.irisa.cairn.simpleGraph.drawGraph.service.IDrawGraphService > > 1 error > at com.google.inject.InjectorImpl.getProvider(InjectorImpl.java:784) > at com.google.inject.InjectorImpl.getProvider(InjectorImpl.java:743) > at com.google.inject.InjectorImpl.getInstance(InjectorImpl.java:793) > at > fr.irisa.cairn.test.simpleGraph.runTimeTest.Launch.Main.main(Main.java: > 25) > > > do you know why? > > jérémie > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
