0

我一直在尝试在我的 GIN 项目中使用Grapher 。但是试图创建一个 Injector 给 InjectorGrapher 并没有奏效。

就在我的代码的第一行:

    Injector injector = Guice.createInjector( new GinModuleAdapter( new MyGinModule() ) );

它崩溃了

 Exception in thread "main" java.lang.AssertionError: should never be actually called
at com.google.gwt.inject.rebind.adapter.GwtDotCreateProvider.get(GwtDotCreateProvider.java:43)
at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
at com.google.inject.Scopes$1$1.get(Scopes.java:54)
at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
at com.google.inject.BoundProviderFactory.get(BoundProviderFactory.java:56)
at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
at com.google.inject.Scopes$1$1.get(Scopes.java:54)
at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
at com.google.inject.InjectorBuilder$1.call(InjectorBuilder.java:200)
at com.google.inject.InjectorBuilder$1.call(InjectorBuilder.java:194)
at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:804)
at com.google.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:194)
at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:176)
at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113)
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)
at com.me.myself.Grapher.main(Grapher.java:20)

是什么赋予了?

4

1 回答 1

3

想通了:我的模块有以下行导致 GinModuleAdapter 阻塞(似乎是一个错误):

 bind(Foo.class).asEagerSingleton();

删除“asEagerSingleton”导致一切正常。但由于这不是我想要的,所以我将其转换为这个,这也有效。

@Provides @Singleton
Foo getFoo() {
    return new Foo();
}
于 2010-03-12T11:16:31.523 回答