我无法使用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 = ""
}
如果我更改了我的数据库名称,则会出现连接错误,因此池正在正确地获取我的配置设置.
最佳答案 我可以在您的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项目中同时使用play-slick和jdbc.
我绝对建议您阅读Play-Slick文档以更好地了解它的工作原理.
希望这可以帮助!