Slick 3配置ProvisionException连接到数据库

时间:2016-01-22 18:07:37

标签: slick slick-2.0 slick-3.0

我是新手,我正在使用3.1.1版和playframework 2.4.6。我在文档http://slick.typesafe.com/doc/3.1.1/database.html中遵循了本指南。我得到的错误是

***ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.RuntimeException: java.lang.ClassNotFoundException: 
org.postgresql.ds.PGSimpleDataSource
  at controllers.Application.<init>(Application.scala:12)
  while locating controllers.Application
    for parameter 1 at router.Routes.<init>(Routes.scala:31)
  while locating router.Routes
  while locating play.api.inject.RoutesProvider
  while locating play.api.routing.Router
1 error***

这是我在SBT中首先提出的这个

libraryDependencies ++= Seq(
  "com.typesafe.slick" %% "slick" % "3.1.1",
  "org.slf4j" % "slf4j-nop" % "1.6.4"
)

然后在我的Application.Conf中我把这个

mydb = {
  dataSourceClass = org.postgresql.ds.PGSimpleDataSource
  properties = {
    databaseName = "mydatabasename"
    user = "postgres"
    password = "mypassword"
  }
  numThreads = 10
}

然后终于在我的控制器中我只有连接字符串 包控制器

import javax.sql.DataSource

import org.mindrot.jbcrypt.BCrypt
import play.api._
import play.api.mvc._
import slick.driver.PostgresDriver.api._
import scala.concurrent.ExecutionContext.Implicits.global


class Application extends Controller {

  val db = Database.forConfig("mydb")
  try {
    // ...
  } finally db.close()




  def index = Action {

    Ok("My First Controller")
  }

}

正如你所看到的那样,我使用postgres驱动程序代替H2,因为我正在使用postgres,这些凭据是正确的并经过验证。

1 个答案:

答案 0 :(得分:1)

您需要将slick-hikaricp和postgresql驱动程序依赖项添加到build.sbt中。

   "com.typesafe.slick" %% "slick-hikaricp" % "3.1.1",
   "org.postgresql" % "postgresql" % "9.4-1206-jdbc4"

如果您不熟悉光滑,我建议您使用光滑的plugin。请看一下光滑的samples