今天早上,我试着把Guice版本从4.0-beta升级到4.0-beta 4,我的MapBinder出现了问题。我有一个扩展JerseyServletModule的基本模块。在configureServlets()方法中,我需要:
MapBinder<String, ExportData> exportDataMapBinder = MapBinder.newMapBinder(binder(),String.class,ExportData.class);
binder().requireExplicitBindings();
bindCommonServices();
install(new V8Module(exportDataMapBinder));我在私有模块中填充地图,如下所示:
exportDataMapBinder.addBinding(VERSION).to(ExportDataV8.class);ExportData是一个接口,ExportDataV8实现了它(我不会粘贴它们以使问题简短)。
使用Guice4.0-beta可以很好地工作,但是使用Guice4.0-beta 4时,我开始出现这样的错误:
1) Explicit bindings are required and com.coveo.ua.data.export.ExportData annotated with @com.google.inject.multibindings.Element(setName=, uniqueId=2, type=MAPBINDER) is not explicitly bound.
while locating com.coveo.ua.data.export.ExportData annotated with @com.google.inject.multibindings.Element(setName=, uniqueId=2, type=MAPBINDER)
at com.google.inject.multibindings.MapBinder$RealMapBinder$1.initialize(MapBinder.java:380)
at com.coveo.ua.config.UsageAnalyticsBaseModule.configureServlets(UsageAnalyticsBaseModule.java:223)有人知道我做错了什么吗?
如果我忘了包括重要的细节,请告诉我。
发布于 2014-11-03 18:52:59
我更新到Guice 4.0 beta 5,它解决了我的问题。正如塔维亚·巴恩斯所建议的。它可能是一个带有beta 4的bug。
发布于 2014-06-26 21:41:15
从您的示例中可以看出,您正在设置主模块所需的详细绑定。只要去掉那个方法,它肯定会成功的。不知道在4.0-beta版本中更改了什么,如果该代码以前有效的话。
你的代码:
MapBinder<String, ExportData> exportDataMapBinder = ...
binder().requireExplicitBindings();应该删除这一行:
binder().requireExplicitBindings();https://stackoverflow.com/questions/24434421
复制相似问题