1

我只是按照这里的建议尝试了 PlaceHistoryMapperWithFactory 。所以我的 AppPlaceHistoryMapper 看起来像这样:

    @WithTokenizers({ InfoPlace.Tokenizer.class, LogPlace.Tokenizer.class })
public interface AppPlaceHistoryMapper extends PlaceHistoryMapperWithFactory<TokenizerFactory> {

}

我也改变了杜松子酒模块:

bind(PlaceHistoryMapperWithFactory.class).to(AppPlaceHistoryMapper.class);

但我不会 gwt 编译。我明白了

[INFO] Compiling module de.stalabw.zensus2011.adb.AuswertungsDB
[INFO]    Scanning for additional dependencies: ...ClientInjectorImpl.java
[INFO]       Adding '57' new generated units
[INFO]          Validating newly compiled units
[INFO]             Ignored 1 unit with compilation errors in first pass.
[INFO] Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[INFO]    [ERROR] Errors in '...PlaceHistoryMapperWithFactoryImpl.java'
[INFO]       [ERROR] Line 10:  The interface PlaceHistoryMapperWithFactory cannot be implemented more than once with different arguments: PlaceHistory
MapperWithFactory<Void> and PlaceHistoryMapperWithFactory
[INFO]    [ERROR] Cannot proceed due to previous errors

我刚刚在我的单元测试中修复了同样的错误。我有一个模拟实现。我刚变

public class PlaceHistoryMapperMock extends AbstractPlaceHistoryMapper<void> implements
AppPlaceHistoryMapper

public class PlaceHistoryMapperMock extends AbstractPlaceHistoryMapper<TokenizerFactory> implements
AppPlaceHistoryMapper

错误消失了。但是如何为我的“真实”代码修复它?

4

2 回答 2

2

问题可能是您GWT.create(PlaceHistoryMapperWithFactory.class)在代码中的某个位置(可能由 GIN 生成),生成器尝试生成一个PlaceHistoryMapperWithFactoryImpl类(该类名是有症状的),该类实现PlaceHistoryMapperWithFactory(传递给GWT.create())和PlaceHistoryMapperWithFactory<Void>(因为生成的类扩展AbstractPlaceHistoryMapper<Void>)。

这实际上取决于您的依赖项如何PlaceHistoryMapperWithFactory在代码中声明。

IMO,你可能应该在你的代码中有依赖PlaceHistoryMapper,而不是一些PlaceHistoryMapperWithFactory. 如果您需要该依赖项(因为这是您调用的地方setFactory),您应该对参数化类型有一个依赖PlaceHistoryMapperWithFactory<TokenizerFactory>项,它必须使用以下方式在 GIN 中映射TypeLiteral

bind(new TypeLiteral<PlaceHistoryMapperWithFactory<TokenizerFactory>>() {}).to(AppPlaceHistoryMapper.class);
于 2012-05-10T14:25:57.880 回答
0

好,我知道了。问题是

bind(PlaceHistoryMapperWithFactory.class).to(AppPlaceHistoryMapper.class);

由于没有 PlaceHistoryMapperWithFactory.class 这将绑定错误的实现。我的解决方案是提供者:

@Provides
@Singleton
public final PlaceHistoryMapperWithFactory<TokenizerFactory> getPlaceHistoryMapper(AppPlaceHistoryMapper hm) {
    return hm;
}

这似乎有效。

于 2012-05-10T14:18:04.840 回答