Guise Multibinder不适用于Play框架

问题描述 投票:1回答:1

在Scala 2.11.8中使用Play 2.5.8。

我具有特征RequestMatcher及其多种实现。我想在服务中插入Seq[RequestMatcher]。我的模块如下所示:

class FeignModule(environment: Environment, configuration: Configuration) extends AbstractModule with AkkaGuiceSupport {
  def configure() = {
    val requestMatcherBinder = Multibinder.newSetBinder(binder(), classOf[RequestMatcher])
    // TODO: Allow for user specified matchers
    requestMatcherBinder.addBinding().to(classOf[DefaultPathMatcher])
    requestMatcherBinder.addBinding().to(classOf[DefaultMethodMatcher])
    requestMatcherBinder.addBinding().to(classOf[DefaultQueriesMatcher])
    requestMatcherBinder.addBinding().to(classOf[DefaultHeadersMatcher])
    requestMatcherBinder.addBinding().to(classOf[DefaultBodyMatcher])

    // TODO: Allow for user specified actors
    bindActor[DefaultRecordingService]("recordingService")
  }
}

注入目标如下:

@javax.inject.Singleton
class FeignService @Inject()(@Named("recordingService") val recordingService: ActorRef,
                             val feignProperties: FeignProperties,
                             val matchers: Seq[RequestMatcher])
                            (implicit val ec: ExecutionContext) {
}

但是

play.api.UnexpectedException:意外的异常[ProvisionException:无法设置,请参见以下错误:

1)没有实现scala.collection.Seq原为界。定位时scala.collection.Seq用于service.FeignService。(FeignService.scala:19)的第三个参数]

我知道Play读取了该模块,因为已经很好地注入了Actor(FeignService的第一个参数)。我在类路径上也有guice-multibindings jar。

怎么了?

将Play 2.5.8与Scala 2.11.8一起使用。我有一个特征RequestMatcher及其多个实现。我想在服务中注入Seq [RequestMatcher]。我的模块如下所示:...

scala playframework dependency-injection guice
1个回答
0
投票

[线程有点旧,但是如果有人(像我一样)有相同的问题:正确的答案是在此问题的注释中,但可能被忽略了:guice Multibinder注入Java集合,而不是scala集合

© www.soinside.com 2019 - 2024. All rights reserved.