我无法巧妙地使用 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._
...
}
我只是将它注入(inject)我的 Controller 中,例如:
@Singleton
class UserController @Inject() (ws: WSClient, cache: CacheApi, userDAO: UserDAO) extends Controller {
...
}
构建.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 中用这个配置解决了这个问题
slick.dbs.default.profile="slick.jdbc.PostgresProfile$"
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.url="jdbc:postgresql://127.0.0.1:5432/[db_name]"
slick.dbs.default.db.user=[name_db]
slick.dbs.default.db.password=[pw_bd]
请注意将数据库名称更改为默认值以外的其他名称。只更改 db_name。
关于scala - 没有绑定(bind) play.api.db.slick.DatabaseConfigProvider 的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38338904/