我有以下文件:

<extend-configuration-property name="gin.ginjector.extensions" value="test.client.gin.ClientInjectorAdditional"/>


我的ClientInjectorAdditional为:

public interface ClientInjectorAdditional extends Ginjector {


    NotificationFetcher getNotificationFetcher();

}


现在,我想在我的入口点类中注入NotificationFetcher。我试过了

public class Test implements EntryPoint {

    private static final ApplicationController controller = GWT.create(ApplicationController.class);

    @Inject
    private NotificationFetcher notificationFetcher;

    @Override

    public void onModuleLoad() {
        controller.init(;
    ...

    }
}


问题是没有注入notificationFetcher。

如何将GWTP与ginjector扩展一起使用?

编辑:

当我使用

 private final ClientInjectorAdditional injector = GWT.create(ClientInjectorAdditional.class);


我收到以下警告:

  No gin modules are annotated on Ginjector interface test.client.gin.ClientInjectorAdditional, did you forget the @GinModules annotation?


编辑:

我试过了:

@GinModules({ClientModule.class})
公共接口ClientInjectorAdditional扩展Ginjector {...}

但这会产生以下错误:

[DEBUG] [test] - Rebinding test.client.gin.ClientInjectorAdditional
    [DEBUG] [test] - Invoking generator com.google.gwt.inject.rebind.GinjectorGenerator
        [ERROR] [test] - Error injecting com.gwtplatform.dispatch.rest.client.ActionMetadataProvider: Unable to create or inherit binding: No @Inject or default constructor found for com.gwtplatform.dispatch.rest.client.ActionMetadataProvider
  Path to required node:

com.gwtplatform.dispatch.rest.client.RestRequestBuilderFactory [com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule.configureDispatch(RestDispatchAsyncModule.java:99)]
 -> com.gwtplatform.dispatch.rest.client.DefaultRestRequestBuilderFactory [com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule.configureDispatch(RestDispatchAsyncModule.java:99)]
 -> com.gwtplatform.dispatch.rest.client.ActionMetadataProvider [@Inject constructor of com.gwtplatform.dispatch.rest.client.DefaultRestRequestBuilderFactory]

        [ERROR] [test] - Error injecting com.gwtplatform.dispatch.rest.client.serialization.JacksonMapperProvider: Unable to create or inherit binding: No @Inject or default constructor found for com.gwtplatform.dispatch.rest.client.serialization.JacksonMapperProvider
  Path to required node:

com.gwtplatform.dispatch.rest.client.serialization.Serialization [com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule.configureDispatch(RestDispatchAsyncModule.java:103)]
 -> com.gwtplatform.dispatch.rest.client.serialization.JsonSerialization [com.gwtplatform.dispatch.rest.client.gin.RestDispatchAsyncModule.configureDispatch(RestDispatchAsyncModule.java:103)]
 -> com.gwtplatform.dispatch.rest.client.serialization.JacksonMapperProvider [@Inject constructor of com.gwtplatform.dispatch.rest.client.serialization.JsonSerialization]

[ERROR] [test] - Deferred binding failed for 'test.client.gin.ClientInjectorAdditional'; expect subsequent failures
[ERROR] [test] - Failed to create an instance of 'test.client.test' via deferred binding
[ERROR] [test] - Unable to load module entry point class test.client.test (see associated exception for details)
[ERROR] [test] - Failed to load module 'test' from user agent 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36' at http-server.fritz.box:61196

最佳答案

GWTP与其所有演示者和视图获取者自动创建ginjector。
它还支持为非GWTP对象扩展此ginjector。
这是您的操作方式:

一种。定义一个接口,让它在some.package.client包中命名为GinjectorExtensions

package some.package.client;

public interface GinjectorExtensions {
    //your objects here
    MyConstants getMyConstants();
    MyMessages MyMessages();
    MyRequestFactory getRequestFactory();
}


b。编辑您的GWT模块xml文件以包含以下行(这告诉GWTP将您的代码行添加到它的autogen Ginjector中):

   <set-configuration-property name="gin.ginjector.extensions"
                              value="some.package.client.GinjectorExtensions"/>


然后,您只需在任何地方@Inject您的对象,一切都将按预期方式工作。

编辑:检查完您的代码后,只需从ClientInjectorAdditional中删除“ extends Ginjector”,一切都会正常。

09-10 21:55