Closed matterche closed 7 years ago
Hmm, I can't reproduce this. I made a new Play 2.6.5 project and used markscheider 2.6.0 as dependency. Then I added some module with named binding like this:
import play.api.inject._
import play.api.Configuration
import play.api.Environment
class TestModule extends Module {
def bindings(env: Environment, conf: Configuration) = Seq(
bind[Counter].qualifiedWith("count").to[AtomicCounter]
)
}
Also the default syntax works:
import com.google.inject.AbstractModule
import com.google.inject.name.Names
class TestModule extends AbstractModule {
def configure() = {
bind(classOf[Counter]).annotatedWith(Names.named("count")).to(classOf[AtomicCounter])
}
}
I used the module like so:
@Singleton
class CountController @Inject() (cc: ControllerComponents,
@Named("count") counter: Counter) extends AbstractController(cc) {...}
And everything worked fine. You seemed to have used some other bind syntax though? And from the error it looks more related to Slick...
Yep, you're right. I stopped investigating the issue while also trying to reproduce it with a simple project without success. My goal was to find out whether it makes sense to report a bug to the Play team. To be honest my conclusion was an educated guess ;)
I can reproduce the issue in a project where we use play.api.libs.concurrent.AkkaGuiceSupport
and bind actors this way:
class EventProcessingJobsModule extends AbstractModule with AkkaGuiceSupport {
def configure() = {
bindActor[SendOrdersActor]("send-orders-actor")
bindActor[SendProducedEventsActor]("send-produced-events-actor")
bindActor[EventStorageActor]("event-storage-actor")
}
}
In addition we're using SlickModule
provided by play-slick.
Both cause the exception.
Ok, tried this in my simple project:
class TestModule extends AbstractModule with AkkaGuiceSupport {
def configure() = {
bind(classOf[Counter]).annotatedWith(Names.named("count")).to(classOf[AtomicCounter])
bindActor[CounterActor]("count-actor")
}
}
and
@Singleton
class CountController @Inject() (cc: ControllerComponents,
@Named("count") counter: Counter,
@Named("count-actor") myActor: ActorRef ) extends AbstractController(cc) {...}
And it still works. Let's see what happens when I drop Slick in the mix :)
Ok, added play-slick to the project
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-slick" % "3.0.1",
"com.typesafe.play" %% "play-slick-evolutions" % "3.0.1",
"com.h2database" % "h2" % "1.4.196"
)
and then used the db in the project
@Singleton
class AtomicCounter @Inject()(dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext) extends Counter {
private val dbConfig = dbConfigProvider.get[JdbcProfile]
dbConfig.db.run(sql"SELECT 1".as[Int])
...}
(together with the Actor DI previously mentioned). And still everything works. Needs to have something to do with your special setup...
Last test: Made it a named database, because that's mentioned in your stacktrace
@Singleton
class AtomicCounter @Inject()(@NamedDatabase("test") dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext) extends Counter {...}
Still works fine. Hard to reproduce :)
Thanks a lot for your support!
Looks like I found my "special configuration". I overlooked that Guice DI support moved to a separate module. @alexkops If you remove guice from libraryDependencies
of the example project you should be able to reproduce the issue. I added it to my project and it just works.
Steps to reproduce:
bind[MyClass]("some-identifier")
Actual Behaviour
During startup an exception is thrown:
Findings
markscheider currently depends on Play 2.6.0. It looks like some incompatible change has been introduced in
com.typesafe.play.play-guice
between 2.6.0 and 2.6.5.Workaround
Pin
com.typesafe.play.play-guice
version to 2.6.5 in build.sbt: