java - GWT GIN - 简单的用例失败(EventBus)

标签 java gwt

Gin 模块:

public class InjectorModule extends AbstractGinModule {
    @Override
    protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    }
}

注入(inject)器:

@GinModules(InjectorModule.class)
public interface Injector extends Ginjector {
    EventBus getEventBus();
}

GWT 模块入口点:

public class Module1 implements EntryPoint {
    private final Injector injector = GWT.create(Injector.class);

    public void onModuleLoad() {        
        injector.getEventBus();
    }   
}

删除对 injector.getEventBus() 的调用使一切正常。调用 injector.getEventBus() 导致:

Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.google.web.bindery.event.shared.EventBus' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at com.XXX.app.client.InjectorImpl.create_Key$type$com$google$web$bindery$event$shared$EventBus$_annotation$$none$$(InjectorImpl.java:72)
at com.XXX.app.client.InjectorImpl.get_Key$type$com$google$web$bindery$event$shared$EventBus$_annotation$$none$$(InjectorImpl.java:86)
at com.XXX.app.client.InjectorImpl.getEventBus(InjectorImpl.java:7)
at com.XXX.app.client.Module1.onModuleLoad(Module1.java:24)

GWT 开发模式说:

23:58:50.287 [ERROR] Deferred binding result type 'com.google.web.bindery.event.shared.EventBus' should not be abstract

最佳答案

如果您使用的是 gwt 2.4:

现在有两个 EventBus(一个已弃用)确保您在注入(inject)器和入口点中使用相同的类型。

关于java - GWT GIN - 简单的用例失败(EventBus),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7943653/

相关文章:

java - Java 编程中的实用程序类

java - Runtime.freeMemory() 和公司或提前分配,以防止后期内存不足错误

java - 二维数组的列和行的总和

javascript - 如何在gwt中处理浏览器事件?

events - GWT 的 BrowserEvent 和 NativeEvent 到底是什么?

java - ListView 中的 CheckBox 与 CheckedTextView

java - Java 中的素数测试是如何工作的?

java - 无法使用 Chrome Web 驱动程序访问 servlet

java - 连接小部件

java - Maven 插件将 -d32 -XstartOnFirstThread 放入 Mac 上的 GWT 启动文件中