没有绑定Slick DatabaseConfigProvider的实现

时间:2018-08-30 15:50:42

标签: scala playframework slick

我刚刚创建了一个虚拟项目,并尝试将Play与Slick集成在一起。我遵循了官方教程,但是很遗憾,没有设法正确运行它。 每当我尝试运行该应用程序时,都会出现以下错误:

play.api.UnexpectedException: Unexpected exception[ProvisionException: Unable to provision, see the following errors:

1) No implementation for play.api.db.slick.DatabaseConfigProvider was bound.
  while locating play.api.db.slick.DatabaseConfigProvider
    for the 1st parameter of com.reciper.repository.UserRepository.<init>(UserRepository.scala:13)

这是我的配置:

build.sbt

scalaVersion := "2.12.2"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test
libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.3"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "3.0.3"
libraryDependencies += "org.postgresql" % "postgresql" % "42.2.4"

application.conf

play.evolutions {
  autoApply = true
}

#Slick for Play
slick.profile = "slick.jdbc.PostgresProfile$"
slick.db.driver = "org.postgresql.Driver"
slick.db.url = "jdbc:postgresql://localhost:5432/reciper"
slick.db.user = "postgres"
slick.db.password = "postgres"

UserRepository.scala

@Singleton
class UserRepository @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
                              (implicit executionContext: ExecutionContext) extends HasDatabaseConfigProvider[PostgresProfile] { ..codehere.. }

HomeController.scala

@Singleton
class HomeController @Inject()(repo: UserRepository) {...}

plugins.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.13")

我已经在它上面苦苦挣扎了3天多了,我失去了希望它能真正起作用的希望。尝试了许多选择,没有一个起作用

您知道什么缺失或错误吗?让我知道您是否需要其他文件 谢谢!

1 个答案:

答案 0 :(得分:1)

按照application.conf中的配置进行操作

build.sbt

"com.typesafe.play" %% "play-slick" % "3.0.3"

application.conf

slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://ec2-54-217-243-228.eu-west-1.compute.amazonaws.com:5432/d344onl0761ji5"
slick.dbs.default.db.user=user
slick.dbs.default.db.password="pass"