How to configure Slick 3.0.0 for Postgres DB (either with or without Hikari).

I have a test application that works fine with an in-memory H2 database. Now I'm trying to connect it to our real database. I either get an internal Slick exception, or a “No suitable driver” exception, depending on my approach:

Here is my simple test (which, again, works great in memory):

"The glimple data model classes" should { "insert a glimple row in the database" in { val db = Database.forConfig("db.edb") // works on db.h2mem1 val glimples = TableQuery[GPGlimpleModel] val insertGlimples = db.run(glimples += GPGlimple(None, None, 1, true, true, 1)) val count = Await.result(insertGlimples, Duration.Inf) println(count) count must beEqualTo(1) ... 

If I enable the connection pool as indicated here:

 db.edb = { driver = org.postgresql.Driver url = "jdbc:postgresql://db-server-1.hyrax.com:5444/CI_0" user = "xxx" // masked to protect the innocent password = "xxx" // masked to protect the innocent keepAliveConnection = true // connectionPool = disabled } 

As a result, I get the following exception. When trying to decrypt what is happening, I started with the connection pool turned on (for example, "connectionPool = enabled" or just commented on this line). This led to more problems and a very, very long exception (shown at the end of this post).

The head of this exception:

[error] [error] java.lang.NoClassDefFoundError: com / zaxxer / hikari / HikariConfig [error] caused by java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig

And that just doesn't make any sense to me ... because, again, it works great in memory.

And here is the build.sbt driver line for Postgres:

 "org.postgresql" % "postgresql" % "9.4-1201-jdbc41", 

Below is the complete exception ... I sent it to github, as suggested at the end of the trace:

[error] [error] java.lang.NoClassDefFoundError: com / zaxxer / hikari / HikariConfig [error] caused by java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig [error] [error] STACKTRACE [error]
slick.jdbc.HikariCPJdbcDataSource $ .forConfig (JdbcDataSource.scala: 141) [Error]
slick.jdbc.HikariCPJdbcDataSource $ .forConfig (JdbcDataSource.scala: 135) [Error]
slick.jdbc.JdbcDataSource $ .forConfig (JdbcDataSource.scala: 35) [error] slick.jdbc.JdbcBackend $ DatabaseFactoryDef $ class.forConfig (JdbcBackend.scala: 223) [Error]
slick.jdbc.JdbcBackend $$ anon $ 3.forConfig (JdbcBackend.scala: 33) [error] models.TestGlimpleModel $$ anonfun $ 1 $$ anonfun $$ 64 apply $$ anonfun $ apply $ 65.apply (TestGlimpleModel.scala: 166) [Error]
models.TestGlimpleModel $$ anonfun $ 1 $$ anonfun $$ 64 apply $$ anonfun $ apply $ 65.apply (TestGlimpleModel.scala: 158) [Error]
org.specs2.matcher.MatchResult $$ Anon $ 12 $$ anonfun $ asResult $ 1.Apply (MatchResult.scala: 310) [Error]
org.specs2.matcher.MatchResult $$ Anon $ 12 $$ anonfun $ asResult $ 1.Apply (MatchResult.scala: 310) [Error]
org.specs2.execute.ResultExecution $ class.execute (ResultExecution.scala: 25) [Error]
org.specs2.execute.ResultExecution $ .Execute (ResultExecution.scala: 120) [Error]
org.specs2.execute.Result $$ anon $ 10.asResult (Result.scala: 230) [error] org.specs2.execute.AsResult $ .apply (AsResult.scala: 25) [error]
org.specs2.matcher.MatchResult $$ Announcement $ 12.asResult (MatchResult.scala: 310) [error] org.specs2.execute.AsResult $ .apply (AsResult.scala: 25) [Error]
org.specs2.main.CommandLineAsResult $$ Announcement $ 1.asResult (CommandLineAsResult.scala: 17) [Error]
org.specs2.main.CommandLineAsResult $$ anonfun $ apply $ 1.Apply (CommandLineAsResult.scala: 21) [Error]
org.specs2.main.CommandLineAsResult $$ anonfun $ apply $ 1.Apply (CommandLineAsResult.scala: 21) [Error]
org.specs2.specification.dsl.mutable.ExampleDsl1 $ BlockExample $$ anonfun $$ more than $ more than $ 1.Apply (ExampleDsl.scala: 39) [Error]
org.specs2.specification.dsl.mutable.ExampleDsl1 $ BlockExample $$ anonfun $$ more than $ more than $ 1.Apply (ExampleDsl.scala: 39) [Error]
org.specs2.specification.core.Execution $$ anonfun $ withEnv $ 1 $$ anonfun $ apply $ 3.Apply (Execution.scala: 120) [Error]
org.specs2.execute.ResultExecution $ class.execute (ResultExecution.scala: 25) [Error]
org.specs2.execute.ResultExecution $ .Execute (ResultExecution.scala: 120) [Error]
org.specs2.execute.Result $$ anon $ 10.asResult (Result.scala: 230) [error] org.specs2.execute.AsResult $ .apply (AsResult.scala: 25) [error]
org.specs2.specification.core.Execution $$ anonfun $ withEnv $ 1.Apply (Execution.scala: 120) [Error]
org.specs2.specification.core.Execution $$ anonfun $ withEnv $ 1.Apply (Execution.scala: 120) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2 $$ anonfun $ apply $ 2.Apply (Execution.scala: 70) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2 $$ anonfun $ apply $ 2.Apply (Execution.scala: 70) [Error]
org.specs2.specification.core.Execution.setResult (Execution.scala: 76) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2.Apply (Execution.scala: 70) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2.Apply (Execution.scala: 70) [error] scala.Option.fold (Option.scala: 158) [error]
org.specs2.specification.core.Execution.execute (Execution.scala: 70) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1 $$ anonfun $ apply $ 6.apply (Executor.scala: 132) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1 $$ anonfun $ apply $ 6.apply (Executor.scala: 130) [Error]
org.specs2.specification.core.Fragment.updateExecution (Fragment.scala: 44) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1.Apply (Executor.scala: 130) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1.Apply (Executor.scala: 129) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1.executedFragment $ lzycompute $ 1 (Executor.scala: 104) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1.org $ specs2 $ process $ specification $ DefaultExecutor $ class $$ anonfun $$ executedFragment $ 1 (Executor.scala: 104) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1 $$ anonfun $ 3.Apply (Executor.Scala: 109) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1 $$ anonfun $ 3.Apply (Executor.scala: 109) [Error]
scalaz.concurrent.Task $$ anonfun $ delay $ 1.apply (Task.scala: 272) [error] scalaz.concurrent.Task $$ anonfun $ delay $ 1.apply (Task.scala: 272) [error] scalaz.concurrent. Task $$ anonfun $ pause $ 1 $$ anonfun $ 4.Apply (Task.scala: 280) [Error]
scalaz.concurrent.Task $$ anonfun $ pause $ 1 $$ anonfun $ 4.Apply (Task.scala: 280) [error] scalaz.concurrent.Task $ .Try (Task.scala: 385) [error]
scalaz.concurrent.Task $$ anonfun $ suspend $ 1.Apply (Task.scala: 280) [Error]
scalaz.concurrent.Task $$ anonfun $ suspend $ 1.Apply (Task.scala: 280) [error] scalaz.concurrent.Future.step (Future.scala: 111) [error]
scalaz.concurrent.Future.listen (Future.scala: 76) [error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 310) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 309) [error] scala.collection.Iterator $ class.foreach (Iterator.scala: 750) [ Error]
scala.collection.AbstractIterator.foreach (Iterator.scala: 1202) [error] scala.collection.IterableLike $ class.foreach (IterableLike.scala: 72) [error] scala.collection.AbstractIterable.foreach (Iterable.scala: 54) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 309) [Error]
scalaz.concurrent.Future $$ Annon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 305) [error] scalaz.concurrent.Future.listen (Future.scala: 80) [error]
scalaz.concurrent.Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [Error]
scalaz.concurrent.Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [error] scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free.resume (Free.scala: 73) [error]
scalaz.Free.go2 $ 1 (Free.scala: 118) [error]
scalaz.Free.go (Free.scala: 122) [error]
scalaz.Free.run (Free.scala: 172) [error]
scalaz.concurrent.Future.listen (Future.scala: 77) [error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 310) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 309) [error] scala.collection.Iterator $ class.foreach (Iterator.scala: 750) [ Error]
scala.collection.AbstractIterator.foreach (Iterator.scala: 1202) [error] scala.collection.IterableLike $ class.foreach (IterableLike.scala: 72) [error] scala.collection.AbstractIterable.foreach (Iterable.scala: 54) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 309) [Error]
scalaz.concurrent.Future $$ Annon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 305) [error] scalaz.concurrent.Future.listen (Future.scala: 80) [error]
scalaz.concurrent.Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [Error]
scalaz.concurrent.Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [error] scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free.resume (Free.scala: 73) [error]
scalaz.Free.go2 $ 1 (Free.scala: 118) [error]
scalaz.Free.go (Free.scala: 122) [error]
scalaz.Free.run (Free.scala: 172) [error]
scalaz.concurrent.Future.listen (Future.scala: 77) [error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 310) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 309) [error] scala.collection.Iterator $ class.foreach (Iterator.scala: 750) [ Error]
scala.collection.AbstractIterator.foreach (Iterator.scala: 1202) [error] scala.collection.IterableLike $ class.foreach (IterableLike.scala: 72) [error] scala.collection.AbstractIterable.foreach (Iterable.scala: 54) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 309) [Error]
scalaz.concurrent.Future $$ Annon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 305) [error] scalaz.concurrent.Future.listen (Future.scala: 80) [error]
scalaz.concurrent.Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [Error]
scalaz.concurrent. Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [error] scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free.resume (Free.scala: 73) [error]
scalaz.Free.go2 $ 1 (Free.scala: 118) [error]
scalaz.Free.go (Free.scala: 122) [error]
scalaz.Free.run (Free.scala: 172) [error]
scalaz.concurrent.Future.listen (Future.scala: 77) [error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 310) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 309) [error] scala.collection.Iterator $ class.foreach (Iterator.scala: 750) [ Error]
scala.collection.AbstractIterator.foreach (Iterator.scala: 1202) [error] scala.collection.IterableLike $ class.foreach (IterableLike.scala: 72) [error] scala.collection.AbstractIterable.foreach (Iterable.scala: 54) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 309) [Error]
scalaz.concurrent.Future $$ Annon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 305) [error] scalaz.concurrent.Future.listen (Future.scala: 80) [error]
scalaz.concurrent.Future.runAsync (Future.scala: 143) [error]
scalaz.concurrent.Future.run (Future.scala: 160) [error]
scalaz.concurrent.Task.attemptRun (Task.scala: 104) [error]
org.specs2.control.ActionT $ .fromTask (ActionT.scala: 125) [error]
org.specs2.control.ActionTSupport $ class.fromTask (ActionT.scala: 188) [Error]
org.specs2.control.package $ Actions $ .fromTask (package.scala: 29) [error] org.specs2.reporter.Reporter $$ anonfun $ report $ 1.Apply (Reporter.scala: 47) [Error]
org.specs2.reporter.Reporter $$ anonfun $ report $ 1.Apply (Reporter.scala: 37) [Error]
org.specs2.runner.SbtRunner $$ anonfun $ specificationRun $ 1 $$ anonfun $ 2.Apply (SbtRunner.scala: 75) [Error]
org.specs2.runner.SbtRunner $$ anonfun $ specificationRun $ 1 $$ anonfun $ 2.Apply (SbtRunner.scala: 75) [Error]
org.specs2.control.ActionT $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 2.Apply (ActionT.scala: 36) [Error]
org.specs2.control.ActionT $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 2.Apply (ActionT.scala: 36) [Error]
org.specs2.control.StatusT $$ anonfun $ flatMap $ 1.Apply (StatusT.scala: 20) [Error]
org.specs2.control.StatusT $$ anonfun $ flatMap $ 1.Apply (StatusT.scala: 19) [error] scala.Function1 $$ anonfun $ andThen $ 1.apply (Function1.scala: 55) [error] scalaz.WriterT $ $ anonfun $ flatMapF $ 1.apply (WriterT.scala: 63) [error] scalaz.WriterT $$ anonfun $ flatMapF $ 1.apply (WriterT.scala: 62) [Error]
scalaz.effect.IO $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 9.apply (IO.scala: 62) [Error]
scalaz.effect.IO $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 9.apply (IO.scala: 61) [Error]
scalaz.Free $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 1.Apply (Free.scala: 60) [Error]
scalaz.Free $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 1.Apply (Free.scala: 60) [error] scalaz.Free.resume (Free.scala: 72) [error]
scalaz.Free.go2 $ 1 (Free.scala: 118) [error]
scalaz.Free.go (Free.scala: 122) [error]
scalaz.Free.run (Free.scala: 172) [error]
scalaz.effect.IO $ class.unsafePerformIO (IO.scala: 22) [error]
scalaz.effect.IOFunctions $$ Anon $ 6.unsafePerformIO (IO.scala: 227) [Error]
org.specs2.runner.SbtRunner $$ anonfun $ newTask $ 1 $$ Anon $ 4.execute (SbtRunner.scala: 40) [error] sbt.ForkMain $ Run $ 2.call (ForkMain.java:294) [error]
sbt.ForkMain $ Run $ 2.call (ForkMain.java:284) [error]
java.util.concurrent.FutureTask.run (FutureTask.java:266) [error]
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) [Error]
java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:617) [error] java.lang.Thread.run (Thread.java:745) [error] [error]
CALLED by java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig [error]
java.net.URLClassLoader $ 1.run (URLClassLoader.javahaps72) [error]
java.net.URLClassLoader $ 1.run (URLClassLoader.javahaps61) [error]
java.security.AccessController.doPrivileged (native method) [error]
java.net.URLClassLoader.findClass (URLClassLoader.javahaps60) [error]
java.lang.ClassLoader.loadClass (ClassLoader.java:424) [error]
sun.misc.Launcher $ AppClassLoader.loadClass (Launcher.java:308) [error] java.lang.ClassLoader.loadClass (ClassLoader.javahaps57) [error]
slick.jdbc.HikariCPJdbcDataSource $ .forConfig (JdbcDataSource.Scala: 141) [Error]
slick.jdbc.HikariCPJdbcDataSource $ .forConfig (JdbcDataSource.scala: 135) [Error]
slick.jdbc.JdbcDataSource $ .forConfig (JdbcDataSource.scala: 35) [error] slick.jdbc.JdbcBackend $ DatabaseFactoryDef $ class.forConfig (JdbcBackend.scala: 223) [Error]
slick.jdbc.JdbcBackend $$ anon $ 3.forConfig (JdbcBackend.scala: 33) [error] models.TestGlimpleModel $$ anonfun $ 1 $$ anonfun $$ 64 apply $$ anonfun $ apply $ 65.apply (TestGlimpleModel.scala: 166) [Error]
models.TestGlimpleModel $$ anonfun $ 1 $$ anonfun $$ 64 apply $$ anonfun $ apply $ 65.apply (TestGlimpleModel.scala: 158) [Error]
org.specs2.matcher.MatchResult $$ Anon $ 12 $$ anonfun $ asResult $ 1.Apply (MatchResult.scala: 310) [Error]
org.specs2.matcher.MatchResult $$ Anon $ 12 $$ anonfun $ asResult $ 1.Apply (MatchResult.scala: 310) [Error]
org.specs2.execute.ResultExecution $ class.execute (ResultExecution.scala: 25) [Error]
org.specs2.execute.ResultExecution $ .Execute (ResultExecution.scala: 120) [Error]
org.specs2.execute.Result $$ anon $ 10.asResult (Result.scala: 230) [error] org.specs2.execute.AsResult $ .apply (AsResult.scala: 25) [error]
org.specs2.matcher.MatchResult $$ Announcement $ 12.asResult (MatchResult.scala: 310) [error] org.specs2.execute.AsResult $ .apply (AsResult.scala: 25) [Error]
org.specs2.main.CommandLineAsResult $$ Announcement $ 1.asResult (CommandLineAsResult.scala: 17) [Error]
org.specs2.main.CommandLineAsResult $$ anonfun $ apply $ 1.Apply (CommandLineAsResult.scala: 21) [Error]
org.specs2.main.CommandLineAsResult $$ anonfun $ apply $ 1.Apply (CommandLineAsResult.scala: 21) [Error]
org.specs2.specification.dsl.mutable.ExampleDsl1 $ BlockExample $$ anonfun $$ more than $ more than $ 1.Apply (ExampleDsl.scala: 39) [Error]
org.specs2.specification.dsl.mutable.ExampleDsl1 $ BlockExample $$ anonfun $$ more than $ more than $ 1.Apply (ExampleDsl.scala: 39) [Error]
org.specs2.specification.core.Execution $$ anonfun $ withEnv $ 1 $$ anonfun $ apply $ 3.Apply (Execution.scala: 120) [Error]
org.specs2.execute.ResultExecution $ class.execute (ResultExecution.scala: 25) [Error]
org.specs2.execute.ResultExecution $ .Execute (ResultExecution.scala: 120) [Error]
org.specs2.execute.Result $$ anon $ 10.asResult (Result.scala: 230) [error] org.specs2.execute.AsResult $ .apply (AsResult.scala: 25) [error]
org.specs2.specification.core.Execution $$ anonfun $ withEnv $ 1.Apply (Execution.scala: 120) [Error]
org.specs2.specification.core.Execution $$ anonfun $ withEnv $ 1.Apply (Execution.scala: 120) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2 $$ anonfun $ apply $ 2.Apply (Execution.scala: 70) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2 $$ anonfun $ apply $ 2.Apply (Execution.scala: 70) [Error]
org.specs2.specification.core.Execution.setResult (Execution.scala: 76) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2.Apply (Execution.scala: 70) [Error]
org.specs2.specification.core.Execution $$ anonfun $ execute $ 2.Apply (Execution.scala: 70) [error] scala.Option.fold (Option.scala: 158) [error]
org.specs2.specification.core.Execution.execute (Execution.scala: 70) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1 $$ anonfun $ apply $ 6.apply (Executor.scala: 132) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1 $$ anonfun $ apply $ 6.apply (Executor.scala: 130) [Error]
org.specs2.specification.core.Fragment.updateExecution (Fragment.scala: 44) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1.Apply (Executor.scala: 130) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ executeFragment $ 1.Apply (Executor.scala: 129) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1.executedFragment $ lzycompute $ 1 (Executor.scala: 104) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1.org $ specs2 $ process $ specification $ DefaultExecutor $ class $$ anonfun $$ executedFragment $ 1 (Executor.scala: 104) [Error]
org.specs2.specification.process.DefaultExecutor $$ anonfun $ sequencedExecution $ 1 $$ anonfun $ 3.Apply (Executor.Future $$ anonfun $ listen $ 1 $$ anonfun $ apply $ 4.Apply (Future.scala: 80) [error] scalaz .Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free $$ anonfun $ map $ 1.apply (Free.scala: 52) [error]
scalaz.Free.resume (Free.scala: 73) [error]
scalaz.Free.go2 $ 1 (Free.scala: 118) [error]
scalaz.Free.go (Free.scala: 122) [error]
scalaz.Free.run (Free.scala: 172) [error]
scalaz.concurrent.Future.listen (Future.scala: 77) [error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 310) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2 $$ anonfun $ apply $ 10.apply (Future.scala: 309) [error] scala.collection.Iterator $ class.foreach (Iterator.scala: 750) [ Error]
scala.collection.AbstractIterator.foreach (Iterator.scala: 1202) [error] scala.collection.IterableLike $ class.foreach (IterableLike.scala: 72) [error] scala.collection.AbstractIterable.foreach (Iterable.scala: 54) [Error]
scalaz.concurrent.Future $$ Anon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 309) [Error]
scalaz.concurrent.Future $$ Annon $ 1 $$ anonfun $ reduceUnordered $ 2.Apply (Future.scala: 305) [error] scalaz.concurrent.Future.listen (Future.scala: 80) [error]
scalaz.concurrent.Future.runAsync (Future.scala: 143) [error]
scalaz.concurrent.Future.run (Future.scala: 160) [error]
scalaz.concurrent.Task.attemptRun (Task.scala: 104) [error]
org.specs2.control.ActionT $ .fromTask (ActionT.scala: 125) [error]
org.specs2.control.ActionTSupport $ class.fromTask (ActionT.scala: 188) [Error]
org.specs2.control.package $ Actions $ .fromTask (package.scala: 29) [error] org.specs2.reporter.Reporter $$ anonfun $ report $ 1.Apply (Reporter.scala: 47) [Error]
org.specs2.reporter.Reporter $$ anonfun $ report $ 1.Apply (Reporter.scala: 37) [Error]
org.specs2.runner.SbtRunner $$ anonfun $ specificationRun $ 1 $$ anonfun $ 2.Apply (SbtRunner.scala: 75) [Error]
org.specs2.runner.SbtRunner $$ anonfun $ specificationRun $ 1 $$ anonfun $ 2.Apply (SbtRunner.scala: 75) [Error]
org.specs2.control.ActionT $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 2.Apply (ActionT.scala: 36) [Error]
org.specs2.control.ActionT $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 2.Apply (ActionT.scala: 36) [Error]
org.specs2.control.StatusT $$ anonfun $ flatMap $ 1.Apply (StatusT.scala: 20) [Error]
org.specs2.control.StatusT $$ anonfun $ flatMap $ 1.Apply (StatusT.scala: 19) [error] scala.Function1 $$ anonfun $ andThen $ 1.apply (Function1.scala: 55) [error] scalaz.WriterT $ $ anonfun $ flatMapF $ 1.apply (WriterT.scala: 63) [error] scalaz.WriterT $$ anonfun $ flatMapF $ 1.apply (WriterT.scala: 62) [Error]
scalaz.effect.IO $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 9.apply (IO.scala: 62) [Error]
scalaz.effect.IO $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 9.apply (IO.scala: 61) [Error]
scalaz.Free $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 1.Apply (Free.scala: 60) [Error]
scalaz.Free $$ anonfun $ flatMap $ 1 $$ anonfun $ apply $ 1.Apply (Free.scala: 60) [error] scalaz.Free.resume (Free.scala: 72) [error]
scalaz.Free.go2 $ 1 (Free.scala: 118) [error]
scalaz.Free.go (Free.scala: 122) [error]
scalaz.Free.run (Free.scala: 172) [error]
scalaz.effect.IO $ class.unsafePerformIO (IO.scala: 22) [error]
scalaz.effect.IOFunctions $$ Anon $ 6.unsafePerformIO (IO.scala: 227) [Error]
org.specs2.runner.SbtRunner $$ anonfun $ newTask $ 1 $$ Anon $ 4.execute (SbtRunner.scala: 40) [error] sbt.ForkMain $ Run $ 2.call (ForkMain.java:294) [error]
sbt.ForkMain $ Run $ 2.call (ForkMain.java:284) [error]
java.util.concurrent.FutureTask.run (FutureTask.java:266) [error]
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) [Error]
java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:617) [error] java.lang.Thread.run (Thread.java:745) [error] [error] [error] This is similar to specs2 exception. .. [error] Please report this with the previous stack at http://github.com/etorreborre/specs2/issues

+6
source share
2 answers

One solution with a basic user on application.conf

 play.modules.enabled += "modules.DatabaseModule" MyNameIs = { database = { driver = org.postgresql.Driver url = "jdbc:postgresql://localhost:5432/databasename" user = "postgreuser" password = "" numThreads = 10 connectionTimeout = 5000 validationTimeout = 5000 } dispatcher { fork-join-executor { parallelism-factor = 2 parallelism-max = 20 } } 

in a dir application you can create a database module like this

 import javax.inject.{Provider, Inject, Singleton} import com.google.inject.AbstractModule import com.typesafe.config.Config import play.api.inject.ApplicationLifecycle import play.api.{Configuration, Environment} import slick.jdbc.JdbcBackend import scala.concurrent.Future class DatabaseModule(environment: Environment, configuration: Configuration) extends AbstractModule { override def configure(): Unit = { bind(classOf[Config]).toInstance(configuration.underlying) bind(classOf[slick.jdbc.JdbcBackend.Database]).toProvider(classOf[DatabaseProvider]) bind(classOf[models.UserDAO]).asEagerSingleton() } } @Singleton class DatabaseProvider @Inject() (config: Config, lifecycle: ApplicationLifecycle) extends Provider[slick.jdbc.JdbcBackend.Database] { private val db = slick.jdbc.JdbcBackend.Database.forConfig("MyNameIs.database", config) lifecycle.addStopHook { () => Future.successful(db.close()) } override def get(): JdbcBackend.DatabaseDef = db } 

In the application / models: UserDAO

 import java.sql.Date import javax.inject.{Inject, Singleton} import com.typesafe.config.Config import slick.driver.PostgresDriver.api._ import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global case class User(id: Option[Long] = None, name: String, firstname: String, email: String, password: String, birthday: Option[Date] = None, signDate: Option[Date] = Some(new Date(System.currentTimeMillis))) @Singleton class UserDAO @Inject()(config: Config, db: Database) { private val users = TableQuery[Users] override def delete(ids: Long*): Future[Boolean] = { Future.sequence(for (id <- ids) yield { db.run(users.filter(_.id === id).delete).map(_ == 1) }).map { _.find(i => i == false) == None } } def insert(user: User): Future[Unit] = db.run(users += user).map{()} override def update(obj: User): Future[Boolean] = ??? override def create(obj: User): Future[Boolean] = db.run(users += obj).map(_ == 1) override def all: Future[Seq[User]] = db.run(users.result) private class Users(tag: slick.lifted.Tag) extends Table[User](tag, "user") { type S = String type D = Date type L = Long // attribute name in table database def id = column[L](ID, O.AutoInc, O.PrimaryKey) def name = column[S](NAME) def password = column[S](PASSWORD) def firstname = column[S](FIRSTNAME) def email = column[S](EMAIL) def birthday = column[D](BIRTHDAY) def signDate = column[D](SIGN_DATE) override def * = (id.?, name, firstname, email, password, birthday.?, signDate.?) <> ((User.apply _) .tupled, User.unapply _) } } 

On Application.scala controllers

 @Singleton class Application @Inject()(userdao: UserDAO) extends Controller { code } 

and in the route file:

 # Home page GET / @controllers.Application.index 
+5
source

Working example for me:

application.conf

 database { dataSourceClass = org.postgresql.ds.PGSimpleDataSource properties = { databaseName = "some_db" user = "local" password = "local" } numThreads = 10 } 

build.sbt

 libraryDependencies ++= Seq( "com.typesafe.slick" %% "slick" % "3.0.0", "com.zaxxer" % "HikariCP" % "2.4.1", "org.postgresql" % "postgresql" % "9.4-1201-jdbc41", // ... ) 

And then I just call

 Database.forConfig("database") 

Using Java 7, Scala 2.11.6 and sbt 0.13.6.

+2
source

Source: https://habr.com/ru/post/987164/


All Articles