【问题标题】:MVP GWT - problem injecting EventBusMVP GWT - 注入 EventBus 的问题
【发布时间】:2011-07-03 13:01:38
【问题描述】:

奇怪的问题,当我注入 EventBus 时出现异常。该项目是使用 mvp 的 gwt

这里是示例代码。

杜松子酒

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

大家有什么想法吗?

谢谢

编辑:

例外是

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" />

【问题讨论】:

    标签: gwt dependency-injection mvp


    【解决方案1】:

    我认为您缺少确保 EventBus 绑定到 SimpleEventBus 的 AbstractPresenterModule 类:

    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();
    }
    

    【讨论】:

      猜你喜欢
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      相关资源
      最近更新 更多