0
我得到堆棧溢出,但我想我已經確定了這個問題。這個問題是綁定我的面板小部件時的遞歸注入。我遇到的問題是我的PanelWidget將Map作爲參數。問題是,這會造成無限循環。GinMapProvider堆棧溢出
GinMapProvider
GinMapBinder<String, IDashboardWidget> mapBinder = GinMapBinder
.newMapBinder(binder(), String.class, IDashboardWidget.class);
mapBinder.addBinding(IGaugeWidgetModel.class.getName()).to(MockGaugeWidget.class);
mapBinder.addBinding(IPlotWidgetModel.class.getName()).to(PlotWidget.class);
mapBinder.addBinding(ITableWidgetModel.class.getName()).to(TableWidget.class);
mapBinder.addBinding(IPanelWidgetModel.class.getName()).to(PanelWidget.class);
如果我刪除Map<String, IDashboardWidget>
問題消失的過程。
PanelWidget類
@Inject
public PanelWidget(final EventBus eventBus, final Resources resources, Map<String, IDashboardWidget> widgetProvider) {
super(eventBus, resources);
this.widgetProvider = widgetProvider;
initWidget(GWT.<Binder> create(Binder.class).createAndBindUi(this));
widgetsPanel.getElement().getStyle().setPosition(Position.RELATIVE);
this.addDomHandler(widgetSelectedHandler, ClickEvent.getType());
}
我想這也和注入WidgetFactory類但這絲毫沒有任何解決我的問題。我曾希望創建一個單例會阻止它重新創建綁定。
@Inject
@Provides
@Singleton
WidgetFactory widgetFactory(Map<String, IDashboardWidget> widgetProvider) {
return new WidgetFactory(widgetProvider);
}
順便說一下我在GWTTestCase中運行這個,但我不認爲這有什麼區別。
是否您的地圖值取決於PanelWidget?它看起來像我應該像你應該注入一個'地圖<字符串,提供者>' –
托馬斯!你搖滾。將@Inject構造函數參數更改爲Provider解決了該問題。添加答案併發送點數。 –
完成,發佈爲答案。 –