playでDB接続できるようにしたいです
scala+playでdocker上のmysqldbに接続したいです。
発生している問題・エラーメッセージ
Unexpected exception SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30001ms. No source available, here is the exception stack trace: -> java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30001ms. com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:697) com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:196) com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:161) com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100) play.api.db.DefaultDatabase.getConnection(Databases.scala:161) play.api.db.evolutions.DatabaseEvolutions.databaseEvolutions(EvolutionsApi.scala:139) play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:117) play.api.db.evolutions.DatabaseEvolutions.scripts(EvolutionsApi.scala:132) play.api.db.evolutions.DefaultEvolutionsApi.scripts(EvolutionsApi.scala:97) play.api.db.evolutions.ApplicationEvolutions$.$anonfun$runEvolutions$1(ApplicationEvolutions.scala:203) play.api.db.evolutions.ApplicationEvolutions$.withLock(ApplicationEvolutions.scala:229) play.api.db.evolutions.ApplicationEvolutions$.runEvolutions(ApplicationEvolutions.scala:199) play.api.db.evolutions.ApplicationEvolutions.$anonfun$start$1(ApplicationEvolutions.scala:66) play.api.db.evolutions.ApplicationEvolutions.$anonfun$start$1$adapted(ApplicationEvolutions.scala:61) scala.collection.immutable.List.foreach(List.scala:305) play.api.db.evolutions.ApplicationEvolutions.start(ApplicationEvolutions.scala:61) play.api.db.evolutions.ApplicationEvolutions.<init>(ApplicationEvolutions.scala:107) play.api.db.evolutions.ApplicationEvolutionsProvider.get$lzycompute(EvolutionsModule.scala:67) play.api.db.evolutions.ApplicationEvolutionsProvider.get(EvolutionsModule.scala:60) play.api.db.evolutions.ApplicationEvolutionsProvider.get(EvolutionsModule.scala:51) com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:85) com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:77) com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:59) com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:61) com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:168) com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:39) com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:211) com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:182) com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109) com.google.inject.Guice.createInjector(Guice.java:87) com.google.inject.Guice.createInjector(Guice.java:78) play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:200) play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:155) play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:189) play.utils.Threads$.withContextClassLoader(Threads.scala:21) play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:181) play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:141) play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:296) play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:186) akka.stream.impl.fusing.MapAsync$$anon$30.onPush(Ops.scala:1261) akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541) akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423) akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:624) akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:501) akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:599) akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:768) akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:783) akka.actor.Actor.aroundReceive(Actor.scala:533) akka.actor.Actor.aroundReceive$(Actor.scala:531) akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:690) akka.actor.ActorCell.receiveMessage(ActorCell.scala:573) akka.actor.ActorCell.invoke(ActorCell.scala:543) akka.dispatch.Mailbox.processMailbox(Mailbox.scala:269) akka.dispatch.Mailbox.run(Mailbox.scala:230) akka.dispatch.Mailbox.exec(Mailbox.scala:242) java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
該当のソースコード
build.sbt
name := """set""" organization := "com.example" version := "1.0-SNAPSHOT" lazy val root = (project in file(".")).enablePlugins(PlayScala) scalaVersion := "2.13.1" libraryDependencies += guice libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test // Adds additional packages into Twirl //TwirlKeys.templateImports += "com.example.controllers._" // Adds additional packages into conf/routes // play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._" libraryDependencies += jdbc libraryDependencies += evolutions libraryDependencies ++= Seq( "mysql" % "mysql-connector-java" % "5.1.36", "org.scalikejdbc" %% "scalikejdbc" % "3.4.0", "org.scalikejdbc" %% "scalikejdbc-config" % "3.4.0", "org.scalikejdbc" %% "scalikejdbc-play-initializer" % "2.8.0-scalikejdbc-3.4" )
# https://www.playframework.com/documentation/latest/Configuration # Database configuration # ~~~~~ # You can declare as many datasources as you want. # By convention, the default datasource is named `default` # db.default.driver=org.h2.Driver db.default.driver="com.mysql.jdbc.Driver" db.default.url="jdbc:mysql://localhost:3306/test" db.default.username="root" db.default.password="mysql" # ScalikeJDBC original configuration db.default.poolInitialSize=10 db.default.poolMaxSize=10 #db.default.poolValidationQuery= db.default.connectionTimeoutMillis=1000 scalikejdbc.global.loggingSQLAndTime.enabled=true scalikejdbc.global.loggingSQLAndTime.singleLineMode=false scalikejdbc.global.loggingSQLAndTime.logLevel=debug scalikejdbc.global.loggingSQLAndTime.warningEnabled=true scalikejdbc.global.loggingSQLAndTime.warningThresholdMillis=5 scalikejdbc.global.loggingSQLAndTime.warningLogLevel=warn play.modules.enabled += "scalikejdbc.PlayModule" # scalikejdbc.PlayModule doesn't depend on Play's DBModule # play.modules.disabled += "play.api.db.DBModule
試したこと
調べて見ると以下の記事が見つかりました
HikariCP - connection is not available
解決策としてトランザクションサービスメソッドの呼び出し回数を一回にするというものが提示されていましたが、どう変更すればいいのかわかりません
補足情報(FW/ツールのバージョンなど)
環境
win10
scala:2.13.1
play:2.8.0
scalikejdbc:3.4.0
docker:18.03.0-ce
mysql:8.0.19
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。