How to configure HikariCP for Slick 3.0.0 RC1 on Typesafe conf

Guillermo Gutiérrez picture Guillermo Gutiérrez · Mar 24, 2015 · Viewed 8.3k times · Source

I have a Play Application based on the play-scala Typesafe template (Play Scala Seed), and tried to add Slick 3.0.0 to the project and connect to a PostgreSQL database.

First I added the dependencies to build.sbt:

libraryDependencies ++= Seq(
    "com.typesafe.slick" %% "slick" % "3.0.0-RC1",
    "postgresql" % "postgresql" % "9.1-901.jdbc4"
)

Then added the database configuration on application.conf:

brDb = {
  dataSourceClass = org.postgresql.ds.PGSimpleDataSource
  url = "jdbc:postgresql://localhost:5432/test"
  user = "postgres"
  password = "postgres"
  numThreads = 10
}

Note that I haven't disabled explicitly the pooling, so it is enabled by default, and will try to use HikariCP, because as of Slick 3.0.0 RC1, HikariCP support exists and pooling using it is enabled by default.

And in my DAO object, tried to get the database connection like this:

Database.forConfig("brDb")

When I run the app using activator run, I get this error:

RuntimeException: java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariConfig

Then I tried adding HikariCP as a dependency in build.sbt:

libraryDependencies ++= Seq(
    // ...
    "com.zaxxer" % "HikariCP" % "2.3.3",
    // ...
)

Cleaned and recompiled the app using activator clean compile, and runned it again, but I get another error:

RuntimeException: java.lang.UnsupportedClassVersionError: com/zaxxer/hikari/HikariConfig

I think I am missing some configuration, but I am not sure and have not found more info about it. How should I set up the configuration to get the connection pool working?

Answer

Carsten picture Carsten · Mar 24, 2015

That error means that the HikariCP package is compiled for a JRE newer than the one you#re running on. And in fact, if you look at the homepage, you'll see that the version you are using is this:

Java 8 maven artifact:

<dependency>
  <groupId>com.zaxxer</groupId>
  <artifactId>HikariCP</artifactId>
  <version>2.3.5</version>
  <scope>compile</scope>
</dependency>

I suppose you're running on Java 7. For that, add the following to your build.sbt:

libraryDependencies ++= Seq(
  "com.zaxxer" % "HikariCP-java6" % "2.3.3",
)