2012-05-10 10 views
1

提案したようにPlaceHistoryMapperWithFactoryを試しましたhere。だから私のAppPlaceHistoryMapperは、以下のようになります。"PlaceHistoryMapperWithFactoryを複数回実装することはできません..."

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

} 

私はまた、TEHジンモジュール変更:

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<TokenizerFactory> implements 
AppPlaceHistoryMapper 

public class PlaceHistoryMapperMock extends AbstractPlaceHistoryMapper<void> implements 
AppPlaceHistoryMapper 

を変更し、エラーが消えていました。私の「本当の」コードを修正する方法は?

答えて

2

問題は、両方のPlaceHistoryMapperWithFactoryを実装して発電機がPlaceHistoryMapperWithFactoryImplクラスを生成しようとしますそのために(おそらくGINによって生成された)コード内GWT.create(PlaceHistoryMapperWithFactory.class)どこかには、(そのクラス名は症候性である)(それはGWT.create()に渡されていますしているということはおそらくあり)とPlaceHistoryMapperWithFactory<Void>(生成されたクラスがAbstractPlaceHistoryMapper<Void>を拡張するため)。

あなたのコードに依存関係がどのように宣言されているかは、実際にはPlaceHistoryMapperWithFactoryによって異なります。

IMOの場合、おそらくPlaceHistoryMapperWithFactoryではなく、PlaceHistoryMapperのコードに依存する必要があります。あなたの提案は、その後優れている -

bind(new TypeLiteral<PlaceHistoryMapperWithFactory<TokenizerFactory>>() {}).to(AppPlaceHistoryMapper.class); 
+0

THX:、あなたがTypeLiteralを使用してGINにマッピングする必要があるパラメータ化された型PlaceHistoryMapperWithFactory<TokenizerFactory>、上の依存関係を持っている必要があります(あなたがsetFactoryを呼び出すところだから)の場合では、その依存関係を必要とします私のプロバイダ。 – dermoritz

0

わかりました。これは間違った実装を結合する何PlaceHistoryMapperWithFactory.classがないので問題は

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

です。私の解決策はプロバイダーです:

これはうまくいくようです。

関連する問題