没有绑定play.api.db.slick.DatabaseConfigProvider的实现

时间:2016-07-12 21:07:47

标签: scala playframework slick

我无法使用play 2.5.x

我收到以下运行时错误:

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

我的DAO看起来像:

@Singleton
class UserDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) 
extends HasDatabaseConfigProvider[JdbcProfile] {
    import driver.api._

...

}

我只是将它注入我的控制器中,如:

@Singleton
class UserController @Inject() (ws: WSClient, cache: CacheApi, userDAO: UserDAO) extends Controller {
...
}

build.sbt

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  cache,
  ws,
  "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test,
  // database
  jdbc,
  "org.postgresql"     %  "postgresql" % "9.3-1102-jdbc41",
  "com.typesafe.play" %% "play-slick" % "2.0.0"
)

我的application.conf有:

play.db {
  # The combination of these two settings results in "db.default" as the
  # default JDBC pool:
  #config = "db"
  #default = "default"

  # Play uses HikariCP as the default connection pool.  You can override
  # settings by changing the prototype:
  prototype {
    # Sets a fixed JDBC connection pool size of 50
    #hikaricp.minimumIdle = 50
    #hikaricp.maximumPoolSize = 50
  }
}

## JDBC Datasource
db {
  default.driver = org.postgresql.Driver
  default.url = "jdbc:postgresql://localhost/testdb_development"
  default.username = "blankman"
  #default.password = ""
}

如果我更改了我的数据库名称,则会出现连接错误,因此该池正在正确地提取我的配置设置。

2 个答案:

答案 0 :(得分:2)

我可以在您的application.conf中看到的一个问题是它错过了播放特定的配置键。实际上,您应该从application.conf中删除 db 部分,并将其替换为 slick.dbs ,如https://www.playframework.com/documentation/2.5.x/PlaySlick#database-configuration

中所示。

您可能想要做的另一件事是从您的sbt构建文件中删除 jdbc 依赖项,据我所知(基于Play 2.4.x),您不能同时使用这两种游戏 - 同一个Play项目中的光滑和jdbc。

我绝对建议您阅读Play-Slick文档,以便更好地了解它的工作原理。

希望这有帮助!

答案 1 :(得分:0)

我在application.conf中使用此配置解决了这个问题

slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.url="jdbc:postgresql://127.0.0.1:5432/[name_db]"
slick.dbs.default.db.user=[name_db]
slick.dbs.default.db.password=[pw_bd]