Reputation: 24518
Using Play 2.5.8 with Scala 2.11.8.
I've a trait RequestMatcher
and multiple implementations of it. I'd like to have a Seq[RequestMatcher]
injected in my service. My module looks like the following:
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")
}
}
The injection target is as follows:
@javax.inject.Singleton
class FeignService @Inject()(@Named("recordingService") val recordingService: ActorRef,
val feignProperties: FeignProperties,
val matchers: Seq[RequestMatcher])
(implicit val ec: ExecutionContext) {
}
But
play.api.UnexpectedException: Unexpected exception[ProvisionException: Unable to provision, see the following errors:
1) No implementation for scala.collection.Seq was bound. while locating scala.collection.Seq for the 3rd parameter of service.FeignService.(FeignService.scala:19)
I know the module is read by Play because the Actor (1st parameter to FeignService
) is injected just fine. I have the guice-multibindings
jar on classpath too.
What's wrong?
Upvotes: 2
Views: 753
Reputation: 21
Thread is a little old but if anybody (like me) has the same problem: The correct answer is in comments to this question but was probably overlooked: guice Multibinder injects Java collections, not scala collections
Upvotes: 2