0
我使用吉斯在Java中+科特林項目注入算法實現的地圖到一個特定的bean,但我不斷收到吉斯MapBinder
1) No implementation for java.util.Map<java.lang.String, ? extends com.scherule.scheduling.algorithms.SchedulingAlgorithm> annotated with @com.google.inject.name.Named(value=scheduling.algorithms) was bound.
while locating java.util.Map<java.lang.String, ? extends com.scherule.scheduling.algorithms.SchedulingAlgorithm> annotated with @com.google.inject.name.Named(value=scheduling.algorithms)
for the 2nd parameter of com.scherule.scheduling.SchedulingJobConsumer.<init>(SchedulingJobConsumer.kt:17)
while locating com.scherule.scheduling.SchedulingJobConsumer
模塊的定義是這樣定義的:
class AlgorithmsModule : AbstractModule() {
override fun configure() {
MapBinder.newMapBinder(binder(),
String::class.java,
SchedulingAlgorithm::class.java,
Names.named("scheduling.algorithms")
).addBinding("interval-projection").toInstance(IntervalProjectionAlgorithm())
}
}
和呼叫者的代碼是:
@Singleton
class SchedulingJobConsumer
@Inject constructor(
@Named("scheduling.channel") channel: Channel,
@Named("scheduling.algorithms") val schedulers: Map<String, SchedulingAlgorithm>
) : DefaultConsumer(channel) ...
但是當我做
injector.getInstance(Key.get(new TypeLiteral<Map<String, SchedulingAlgorithm>>() {}, named("scheduling.algorithms")))
它在那裏。怎麼了?
嘗試在'val schedulers'的聲明中添加'@ JvmSuppressWildcards'註釋 – yole
將它添加到構造函數聲明中不會改變任何內容。在字段上執行此操作會將錯誤消息修改爲java.util.Map的No實現(...)所以它似乎甚至找不到它。 –
kboom
錯誤消息似乎說它找不到SchedulingAlgorithm的實現。那是如何定義的? – Les