与 play.api.db.DBApi 的绑定已经配置,使用 play-slick 的进化和注入器错误 [英] A binding to play.api.db.DBApi was already configured, evolutions and injector error with play-slick
问题描述
我想在我的 play 项目中引入 slick,所以我在 build.sbt 中添加了以下依赖项:
I want to introduce slick to my play project, so I add the following dependencies to build.sbt:
"com.typesafe.play" %% "play-slick" % "1.0.1" withSources(),
"com.typesafe.play" %% "play-slick-evolutions" % "1.0.1" withSources(),
然后,当我为控制器运行集成规范时,我在 Intellij IDE 和命令行激活器测试中都遇到了以下异常.在谷歌之后我找到了解决方案:https://www.playframework.com/documentation/2.4.x/PlaySlickFAQ#A-binding-to-play.api.db.DBApi-was-already-configured
Then, when I run an integration spec for controller I got following exception both on Intellij IDE and command line activator test. After Google I found the solution: https://www.playframework.com/documentation/2.4.x/PlaySlickFAQ#A-binding-to-play.api.db.DBApi-was-already-configured
在我删除 jdbc 依赖项后,使用命令行时通过了集成规范,但是当我在 Intellij IDE 上运行测试时仍然出现相同的错误,如下错误:在嵌套套件上调用运行时遇到异常 - 无法创建注入器,请参阅以下错误:
After I removed the jdbc dependency, the integration spec passed when I using the command line, however I still got the same error when I run the test on Intellij IDE as following error: Exception encountered when invoking run on a nested suite - Unable to create injector, see the following errors:
1) A binding to play.api.db.DBApi was already configured at play.api.db.DBModule.bindings(DBModule.scala:25):
Binding(interface play.api.db.DBApi to ProviderConstructionTarget(class play.api.db.DBApiProvider)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1).
at play.api.db.slick.evolutions.EvolutionsModule.bindings(EvolutionsModule.scala:15):
Binding(interface play.api.db.DBApi to ConstructionTarget(class play.api.db.slick.evolutions.internal.DBApiAdapter) in interface javax.inject.Singleton) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
1 error
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) A binding to play.api.db.DBApi was already configured at play.api.db.DBModule.bindings(DBModule.scala:25):
Binding(interface play.api.db.DBApi to ProviderConstructionTarget(class play.api.db.DBApiProvider)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1).
at play.api.db.slick.evolutions.EvolutionsModule.bindings(EvolutionsModule.scala:15):
Binding(interface play.api.db.DBApi to ConstructionTarget(class play.api.db.slick.evolutions.internal.DBApiAdapter) in interface javax.inject.Singleton) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:466)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:73)
at com.google.inject.Guice.createInjector(Guice.java:62)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
at play.api.test.FakeApplication.<init>(Fakes.scala:216)
at org.scalatestplus.play.OneServerPerSuite$class.app(OneServerPerSuite.scala:152)
推荐答案
如果你和我一样,你的 build.sbt 中有这样的东西
If you are like me, you have something like this in your build.sbt
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
specs2 % Test,
"mysql" % "mysql-connector-java" % "5.1.37",
"com.typesafe.play" %% "play-slick" % "1.1.1",
"com.typesafe.play" %% "play-slick-evolutions" % "1.1.1"
)
删除 jdbc
libraryDependencies ++= Seq(
//jdbc, //<<---- this one here
cache,
这篇关于与 play.api.db.DBApi 的绑定已经配置,使用 play-slick 的进化和注入器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!