簡體   English   中英

MapBinder需要明確綁定-Guice 4.0 beta4

[英]Explicit binding required with MapBinder - Guice 4.0 beta4

今天早上,我試圖將Guice版本從4.0-beta更新到4.0-beta4,我開始遇到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實現了它(我不會粘貼它們來簡化問題)。

使用guice 4.0-beta可以正常工作,但是使用guice 4.0-beta4時,我開始遇到這樣的錯誤:

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)

有人知道我在做什么錯嗎?

請告訴我是否忘記了重要細節。

從您的示例中可以看到,您正在設置主模塊需要顯式綁定。 只需刪除該方法,它肯定會起作用。 如果該代碼以前可以工作,則不知道4.0-beta中有哪些更改。

您的代碼:

MapBinder<String, ExportData> exportDataMapBinder = ...
binder().requireExplicitBindings();

應該刪除以下行:

binder().requireExplicitBindings();

我更新到了Guice 4.0 beta 5 ,它解決了我的問題。 正如塔維安·巴恩斯(Tavian Barnes)所建議的那樣。 Beta 4可能是一個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM