如何为Postgres DB配置Slick 3.0.0(无论是使用Hikari还是不使用)Typesafe Play conf

我有一个测试应用程序,可以在H2内存数据库中正常工作。现在我试图将它连接到我们的真实数据库。我要么获得内部油滑的异常,或“没有合适的驱动程序”外,根据我的方法:如何为Postgres DB配置Slick 3.0.0(无论是使用Hikari还是不使用)Typesafe Play conf

这里是我的简单测试(再次,似乎工作内存罚款):

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

...

如果我打开了连接池,指出这里:

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

}

我最终得到了以下异常。在试图破译发生的事情时,我开始启用一个连接池(例如,“connectionPool = enabled”或只是评论该行)。这导致了更多的问题和一个非常非常长的例外(显示在这篇文章的末尾)。

是异常的头是:

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

而这只是没有任何意义,我...因为再次,它工作在内存就好了。

这里还有专门用于Postgres的build.sbt车手阵容:

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

以下是完整的例外......我它发布到GitHub上作为跟踪的最后建议:

[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$apply$64$$anonfun$apply$65.apply(TestGlimpleModel.scala:166) [error]
models.TestGlimpleModel$$anonfun$1$$anonfun$apply$64$$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$$anon$12.asResult(MatchResult.scala:310) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.main.CommandLineAsResult$$anon$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$$greater$greater$1.apply(ExampleDsl.scala:39) [error]
org.specs2.specification.dsl.mutable.ExampleDsl1$BlockExample$$anonfun$$greater$greater$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$specification$process$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$suspend$1$$anonfun$4.apply(Task.scala:280) [error]
scalaz.concurrent.Task$$anonfun$suspend$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$$anon$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$$anon$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$$anon$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$$anon$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]
CAUSED BY java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig [error]
java.net.URLClassLoader$1.run(URLClassLoader.java:372) [error]
java.net.URLClassLoader$1.run(URLClassLoader.java:361) [error]
java.security.AccessController.doPrivileged(Native Method) [error]
java.net.URLClassLoader.findClass(URLClassLoader.java:360) [error]
java.lang.ClassLoader.loadClass(ClassLoader.java:424) [error]
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) [error] java.lang.ClassLoader.loadClass(ClassLoader.java:357) [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$apply$64$$anonfun$apply$65.apply(TestGlimpleModel.scala:166) [error]
models.TestGlimpleModel$$anonfun$1$$anonfun$apply$64$$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$$anon$12.asResult(MatchResult.scala:310) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.main.CommandLineAsResult$$anon$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$$greater$greater$1.apply(ExampleDsl.scala:39) [error]
org.specs2.specification.dsl.mutable.ExampleDsl1$BlockExample$$anonfun$$greater$greater$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$specification$process$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$suspend$1$$anonfun$4.apply(Task.scala:280) [error]
scalaz.concurrent.Task$$anonfun$suspend$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$$anon$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$$anon$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$$anon$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$$anon$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 looks like a specs2 exception... [error] Please report it with the preceding stacktrace at http://github.com/etorreborre/specs2/issues

回答:

工作例如:

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",

// ...

)

然后我就叫

Database.forConfig("database") 

使用Java 7,斯卡拉2.11.6和0.13.6 SBT。

回答:

一对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

}

}

与基本用户 解决方案上目录应用程序,你可以创建数据库模块,这样

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

}

上的应用/型号: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

@Singleton 

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

和路由文件:

# Home page 

GET / @controllers.Application.index

以上是 如何为Postgres DB配置Slick 3.0.0(无论是使用Hikari还是不使用)Typesafe Play conf 的全部内容, 来源链接: utcz.com/qa/259856.html

回到顶部