slickslick-2.0slick-3.0

Slick 3 configuration ProvisionException on connecting to the database


I am new to slick and am using version 3.1.1 along with the playframework 2.4.6 . I am following this guide in the documentation http://slick.typesafe.com/doc/3.1.1/database.html . The error I am getting is

***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***

This is what I have first in the SBT I put this

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

Then in my Application.Conf I put this

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

Then finally in my controller I just have the connection string package controllers

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")
  }

}

As you can see I put the postgres driver instead of the H2 since I'm working with postgres and those credentials are the correct ones and verified.


Solution

  • You need to add slick-hikaricp and postgresql driver dependencies into build.sbt.

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

    If you are new to slick, I would like to suggest you should use slick as a plugin. Please take a look play-slick samples.