已经配置了对play.api.db.DBApi的绑定,并且播放变得流畅,并且演变和注入器错误 [英] A binding to play.api.db.DBApi was already configured, evolutions and injector error with play-slick

查看:304
本文介绍了已经配置了对play.api.db.DBApi的绑定,并且播放变得流畅,并且演变和注入器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将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和命令行激活程序测试中都遇到了以下异常.在Google之后,我找到了解决方案: https://www.playframework.com/documentation/2.4.x/PlaySlickFAQ#A-binding-to-play.api.db.DBApi-was-已经配置

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的绑定,并且播放变得流畅,并且演变和注入器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆