我在尝试将postgresql集成到我的播放应用程序时出现此错误:
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 parameter 0 at models.EntryRepo.<init>(EntryRepo.scala:10)
while locating models.EntryRepo
for parameter 0 at controllers.Entries.<init>(Entries.scala:17)
while locating controllers.Entries for parameter 4 at router.Routes.<init>(Routes.scala:39)
while locating router.Routes
while locating play.api.inject.RoutesProvider while locating play.api.routing.Router
我的SBT文件:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.6"
libraryDependencies ++= Seq(
cache,
ws,
specs2 % Test
)
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-slick" % "1.1.1",
"com.typesafe.play" %% "play-slick-evolutions" % "1.1.1",
"org.postgresql" % "postgresql" % "9.4-1201-jdbc4",
"com.typesafe.slick" %% "slick" % "3.1.1",
"com.typesafe.slick" %% "slick-hikaricp" % "3.1.1",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
routesGenerator := InjectedRoutesGenerator
我的application.conf
slicks.dbs.default.driver="slick.driver.PostgresDriver$"
slicks.dbs.default.dataSourceClass="slick.jdbc.DatabaseUrlDataSource"
slicks.dbs.default.db.default.driver = org.postgresql.Driver
slicks.dbs.default.db.default.url = "jdbc:postgresql://localhost:5000/aleksander"
slicks.dbs.default.db.default.user = postgres
slicks.dbs.default.db.default.password = "lelelel"
注射部位
class EntryRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {...}
class Entries @Inject()(entryRepo: EntryRepo) extends Controller {...}
我一直在关注来自激活器的play-slick3模板。我试图尽可能接近模板,但错误仍然存在
答案 0 :(得分:1)
我有类似的问题,我使用的是Play 2.5.x.
在新的 application.conf 中,他们的代码约定已从简单切换变为更多&#34; JSONish&#34;格式化(称为 HOCON )。
db {
foo
}
你可能会被欺骗,认为你应该把
slicks.dbs.default.driver="slick.driver.PostgresDriver$"
slicks.dbs.default.dataSourceClass="slick.jdbc.DatabaseUrlDataSource"
slicks.dbs.default.db.default.driver = org.postgresql.Driver
slicks.dbs.default.db.default.url ="jdbc:postgresql://localhost:5000/aleksander"
slicks.dbs.default.db.default.user = postgres
slicks.dbs.default.db.default.password = "lelelel"
在db {}
个大括号内。然而,在拉了我的头发超过6个小时后,我发现把db配置代码 OUTSIDE 这些大括号解决了我的问题。你可能陷入了类似的陷阱。
当然你可以像以下那样以jsonic方式使用它:
slicks.dbs.default.db { /* your slick configuration */}