奇怪的问题,当我注入(inject) EventBus e 时出现异常。该项目是gwt,使用mvp
这是示例代码。
Gin
public interface AppGinjector extends Ginjector
{
EventBus getEventBus();
PlaceManager getPlaceManager();
}
这里是入口点
public class MvpEntryPoint implements EntryPoint
{
AppGinjector ginjector = GWT.create(AppGinjector.class);
public void onModuleLoad()
{
EventBus eventBus = ginjector.geEventBus();
HelloWorldPanel display = new HelloWorldPanel();
HelloWorldPresenter presenter = new HelloWorldPresenter( display, eventBus );
presenter.bind();
RootPanel.get().add( presenter.getDisplay().asWidget() );
PlaceManager placeManager = ginjector.getPlaceManager();
placeManager.fireCurrentPlace();
}
我使用 gin 1.0 ,gwt-presenter
大家有什么想法吗?
谢谢
编辑:
异常(exception)是
ERROR: Deferred binding result type 'net.customware.gwt.presenter.client.EventBus' should not be abstract.
ERROR: Unable to load module entry point class com.gmgsys.mvpEntryPoint.client.MvpEntryPoint (see associated exception for details). java.lang.RuntimeException: Deferred binding failed for 'net.customware.gwt.presenter.client.EventBus' (did you forget to inherit a required module?)
...........................
还有 gwt.xml
<!-- Specify the app entry point class. -->
<entry-point class='com.gmgsys.mvpEntryPoint.client.MvpEntryPoint'/>
<inherits name='net.customware.gwt.presenter.Presenter' />
<inherits name="com.google.gwt.inject.Inject" />
最佳答案
我认为您缺少 AbstractPresenterModule 类,该类确保 EventBus 绑定(bind)到 SimpleEventBus:
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
应该是这样的:
public class MyClientModule extends AbstractPresenterModule {
protected void configure() {
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
// more bindings here
}
}
并且你必须注释你的 Ginjector
@GinModules({ MyClientModule .class })
public interface AppGinjector extends Ginjector
{
EventBus getEventBus();
PlaceManager getPlaceManager();
}
关于gwt - MVP GWT - 注入(inject) EventBus 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6563025/