scala - 启动时播放错误: No implementation for play. api.db.Database已绑定(bind)

标签 scala playframework-2.5

当我尝试运行 Play 应用程序 (Play 2.5.4) 时,出现以下错误:

ProvisionException: Unable to provision, see the following errors:

1) No implementation for play.api.db.Database was bound.
  while locating play.api.db.Database
    for parameter 0 at ds.qb.manage.ManageQueryBuilder.<init>(ManageQueryBuilder.scala:30)
  while locating ds.qb.manage.ManageQueryBuilder
    for parameter 16 at router.Routes.<init>(Routes.scala:107)
  while locating router.Routes
  while locating play.api.inject.RoutesProvider
  while locating play.api.routing.Router
    for parameter 0 at play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:200)
  while locating play.api.http.JavaCompatibleHttpRequestHandler
  while locating play.api.http.HttpRequestHandler
    for parameter 4 at play.api.DefaultApplication.<init>(Application.scala:221)
  at play.api.DefaultApplication.class(Application.scala:221)
  while locating play.api.DefaultApplication
  while locating play.api.Application

这是我的数据库设置,有什么想法吗?我有两次定义,因为我通过 Slick 和 JDBC 访问数据库。

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
  #}
}

  db.default.driver=com.mysql.jdbc.Driver
  db.default.url="jdbc:mysql://localhost:3306/db2"
  db.default.username=root
  db.default.password=xxxxx


db2 = {
  url = "jdbc:mysql://localhost:3306/db2"
  driver = com.mysql.jdbc.Driver
  connectionPool = disabled
  keepAliveConnection = true
  user=root
  password=xxxxxx
}

更新

build.sbt 文件:

name := """myapp"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)

libraryDependencies += "com.typesafe.slick" %% "slick" % "3.1.1"
libraryDependencies += "com.typesafe.play" %% "play-slick" % "2.0.0"
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.18"
libraryDependencies += "org.pivot4j" % "pivot4j-core" % "0.9" 
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.1.0" 

// properties file
libraryDependencies += "com.typesafe" % "config" % "1.3.0" 

libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.6.4"
libraryDependencies += "log4j" % "log4j" % "1.2.14"

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"

// mondrian
resolvers += "Pentaho Releases" at "http://repository.pentaho.org/artifactory/repo/"

最佳答案

就我而言,application.conf 没有正确的数据库参数

示例

  db.default.driver = org.h2.Driver
  db.default.url = "jdbc:h2:mem:play"
  db.default.username = sa
  db.default.password = ""

关于scala - 启动时播放错误: No implementation for play. api.db.Database已绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38825728/

相关文章:

scala - sbt 排除 slf4j 不起作用

java - 将 Java 代码转换为 Scala 代码

apache-spark - Spark 2.0 与 Play! 2.5

json - Play JSON : turn a Seq[Reads[JsObject]] into one Reads[JsObject]

scala - 在逗号分隔的字符串中获取前 2 个值

Ruby 到 Scala 的代码转换

scala - 在 Scalaz 中为过滤器返回析取编写 Monoid 的更好方法

java - Play Framework 2.5 使用 POST 方法提交表单错误

java - CacheApi 不介意 timeToIdle 的 EhCache 配置

java - 未绑定(bind) play.db.Database 的实现