Java GinMapProvider堆栈溢出
我的堆栈溢出,但我想我已经解决了这个问题。当绑定我的面板小部件时,问题是递归注入。我遇到的问题是,我的PanelWidget将映射作为参数。问题是这样会产生一个无限循环 GinMapProviderJava GinMapProvider堆栈溢出,java,gwt,guice,gwt-gin,Java,Gwt,Guice,Gwt Gin,我的堆栈溢出,但我想我已经解决了这个问题。当绑定我的面板小部件时,问题是递归注入。我遇到的问题是,我的PanelWidget将映射作为参数。问题是这样会产生一个无限循环 GinMapProvider GinMapBinder<String, IDashboardWidget> mapBinder = GinMapBinder .newMapBinder(binder(), String.class, IDashboardWidget.class);
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);
ginmappinder-mappinder=ginmappinder
.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())到(TableWidget.class);
mapBinder.addBinding(IPanelWidgetModel.class.getName()).to(PanelWidget.class);
如果我删除Map
,问题当然会消失
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());
}
@Inject
公共PanelWidget(最终事件总线、最终资源、映射widgetProvider){
超级(事件总线、资源);
this.widgetProvider=widgetProvider;
initWidget(GWT.create(Binder.class).createAndBindUi(this));
widgetsPanel.getElement().getStyle().setPosition(Position.RELATIVE);
this.addDomHandler(widgetSelectedHandler,ClickEvent.getType());
}
我也尝试了这一点,并注入了WidgetFactory类,但这也没有解决我的问题。我曾希望创建一个singleton可以阻止它重新创建绑定
@Inject
@Provides
@Singleton
WidgetFactory widgetFactory(Map<String, IDashboardWidget> widgetProvider) {
return new WidgetFactory(widgetProvider);
}
@Inject
@提供
@独生子女
WidgetFactory WidgetFactory(映射widgetProvider){
返回新的WidgetFactory(widgetProvider);
}
顺便说一句,我在GWTTestCase中运行这个,但我不认为这有什么区别 您可能有循环依赖关系,特别是在地图中放置的某个东西和
PanelWidget
之间
考虑到代码的外观(
WidgetFactory
),我认为您实际上可能需要一个Map
,而不是Map
。这将减少循环依赖性的副作用。您的地图值是否取决于PanelWidget
可能?在我看来,你也许应该注入一个Map
THOMAS!!你太棒了。将@Inject构造函数参数更改为Provider解决了此问题。添加答案,我会发送分数。完成,作为答案发布。