I am trying to use GIN with a GWT app for the first time and am running into what I *believe* is a JAR hell (versioning) issue. I have the following project directory structure:
MyApp/
com.myapp
MyApp.gwt.xml
com.myapp.client
MyAppModule
MyAppActivityMapper
com.myapp.client.plumbing.di
IMyAppGinjector
MyAppModuleInjector
Referenced Libraries/ (this is Eclipse Indigo and these are on project buildpath)
aopalliance.jar
gin-2.0.jar
guice-3.0.jar
guice-assistedinject-3.0.jar
javax.inject.jar
The essential code:
<!-- MyApp.gwt.xml -->
<module rename-to="myAppModule">
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.inject.Inject"/>
<inherits name="com.google.gwt.activity.Activity"/>
<entry-point class="com.myapp.client.MyAppModule"/>
<!-- Configure GWT sourcepath. -->
<source path='client'/>
<source path='shared'/>
</module>
public class MyAppModule implements EntryPoint {
private final IMyAppGinjector injector = GWT.create(IMyAppGinjector.class);
private ActivityManager baseManager;
@Override
public void onModuleLoad() {
baseManager = injector.getBaseManager();
// Lots of other stuff.
}
}
@GinModules(MyAppModuleInjector.class)
public interface IMyAppGinjector extends Ginjector {
public ActivityManager getBaseManager();
}
public class MyAppModuleInjector extends AbstractGinModule {
@Override
protected void configure() {
// Binding for simple things.
bind(EventBus.class).to(SimpleEventBus.class);
// ...etc.
}
@Provides
@Singleton
public ActivityManager getBaseManager() {
ActivityMapper myMapper = new MyAppActivityMapper();
return new ActivityManager(myMapper);
}
}
My
understanding is that annotating the `MyAppModuleInjector#getBaseManager` with the `@Provides` methods allows GIN to automatically select that method as the provider when my `MyAppModule#onModuleLoad()` calls `baseManager = injector.getBaseManager()`. **This may be the cause of my error**, but I have also found evidence that I may have versions of GWT, GIN and Guice that don't play nicely together.
When I run this code locally in Eclipse, I get the following error in the *Development Mode* console:
09:29:44.417 [ERROR] [myAppModule] Generator 'com.google.gwt.inject.rebind.GinjectorGenerator' threw an exception while rebinding 'com.myapp.client.plumbing.di.IMyAppModuleGinjector'
com.google.inject.CreationException: Guice creation errors:
1) No implementation for javax.inject.Provider<com.google.gwt.inject.rebind.GinjectorBindings> was bound.
while locating javax.inject.Provider<com.google.gwt.inject.rebind.GinjectorBindings>
for parameter 4 at com.google.gwt.inject.rebind.GinjectorBindings.<init>(GinjectorBindings.java:196)
at com.google.gwt.inject.rebind.GinjectorGeneratorModule.configure(GinjectorGeneratorModule.java:75)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354)
at com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:152)
at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105)
at com.google.inject.Guice.createInjector(Guice.java:92)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
...I am omitting the rest of this lengthy stack trace for brevity, but it is getting thrown when I
am creating my IMyAppGinjector instance at the top of MyAppModule
I pasted this exception into Google and only found a few other instances of this occurring. The best I found was [this forum post](
http://www.mail-archive.com/google-we...@googlegroups.com/msg59270.html) where the user discovered that he/she had a GIN/Guice combo that was bad. He/she changed versions of those libraries and it looks like it resolved their problem.
I am using:
- GWT - 2.4
- GIN - 2.0
- Guice - 3.0
My only two guesses are:
- I am not using the `@Provides` annotation (or its respective provider method) correctly, in which case, how should I use this?; or
- I have, essentially, a Google JAR hell dilemma
Any ideas? Thanks in advance!