Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No implementation for play.api.db.slick.DatabaseConfigProvider was bound

I can't get slick to work with play 2.5.x

I get the following runtime error:

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

My DAO looks like:

@Singleton
class UserDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) 
extends HasDatabaseConfigProvider[JdbcProfile] {
    import driver.api._

...

}

And I just inject it in my controller like:

@Singleton
class UserController @Inject() (ws: WSClient, cache: CacheApi, userDAO: UserDAO) extends Controller {
...
}

build.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"
)

My application.conf has:

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

If I change my database name I get a connection error, so the pool is picking up my config settings correctly.

like image 611
Blankman Avatar asked Jul 12 '16 21:07

Blankman


2 Answers

One issue I can see with your application.conf is that it misses the play-slick specific configuration keys. In fact, you should remove the db section from your application.conf, and replace it with slick.dbs as shown in https://www.playframework.com/documentation/2.5.x/PlaySlick#database-configuration

Another thing you likely want to do is removing the jdbc dependency from your sbt build file, as to my knowledge (which is based on Play 2.4.x) you can't use both play-slick and jdbc on the same Play project.

I'd definitely suggest you to read the Play-Slick documentation to better understand how it works.

Hope this helps!

like image 164
Mirco Dotta Avatar answered Nov 01 '22 08:11

Mirco Dotta


I solve this problem with this config in 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]

Please note to change database name to something else other than default. Only change db_name.

like image 23
pablopaho Avatar answered Nov 01 '22 07:11

pablopaho