我想将 lagom 连接到 MySQL 数据库,我下载了一个在 Lagom 站点创建的项目。我在 hello-impl pom 中添加了以下依赖项,并在 applicaiont.conf 中配置了数据库详细信息。
<dependency>
<groupId>com.lightbend.lagom</groupId>
<artifactId>lagom-javadsl-persistence-jdbc_${scala.binary.version}</artifactId>
<version>${lagom.version}</version>
</dependency>
应用程序配置文件
db.default {
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost:3306/test"
user = "root"
password = ""
}
jdbc-defaults.slick.profile = "slick.jdbc.MySQLProfile$"
lagom.persistence.jdbc.create-tables.auto = true
之后我运行该应用程序,出现以下错误。什么错误。 我是 lagom 的新手,所以请详细解释一下。
{"name":"akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://hello-impl-application/system/sharding/HelloEntity#976224651]] after [10000 ms]. Message of type [com.lightbend.lagom.javadsl.persistence.CommandEnvelope]. A typical reason for `AskTimeoutException` is that the recipient actor didn't send a reply.","detail":"akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://hello-impl-application/system/sharding/HelloEntity#976224651]] after [10000 ms]. Message of type [com.lightbend.lagom.javadsl.persistence.CommandEnvelope]. A typical reason for `AskTimeoutException` is that the recipient actor didn't send a reply.\r\n\tat akka.pattern.PromiseActorRef$.$anonfun$defaultOnTimeout$1(AskSupport.scala:635)\r\n\tat akka.pattern.PromiseActorRef$.$anonfun$apply$1(AskSupport.scala:650)\r\n\tat akka.actor.Scheduler$$anon$4.run(Scheduler.scala:205)\r\n\tat scala.concurrent.Future$InternalCallbackExecutor$.unbatchedExecute(Future.scala:870)\r\n\tat scala.concurrent.BatchingExecutor.execute(BatchingExecutor.scala:109)\r\n\tat scala.concurrent.BatchingExecutor.execute$(BatchingExecutor.scala:103)\r\n\tat scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:868)\r\n\tat akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(LightArrayRevolverScheduler.scala:328)\r\n\tat akka.actor.LightArrayRevolverScheduler$$anon$4.executeBucket$1(LightArrayRevolverScheduler.scala:279)\r\n\tat akka.actor.LightArrayRevolverScheduler$$anon$4.nextTick(LightArrayRevolverScheduler.scala:283)\r\n\tat akka.actor.LightArrayRevolverScheduler$$anon$4.run(LightArrayRevolverScheduler.scala:235)\r\n\tat java.lang.Thread.run(Thread.java:748)\r\n"}
最佳答案
在使用 MySQL 时,我们需要自己创建数据库。在 Cassandra 中,它会在 conf 文件中定义名称后创建 key 空间,但在 MySQL 中,我们必须手动创建一个数据库,例如 test 在您的情况下 ->
create database test;
那么你就不会遇到 Ask timed out 异常了。
关于mysql - Lagom 与 MySQL Db 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53821490/