播放框架,SQLTimeoutException

时间:2017-01-28 16:26:01

标签: mysql playframework

在Play框架中,我的第一个(编译后)请求以SQLTimeoutException after 1001 ms结束 错误文本:

[error] application - 

! @72p3a11me - Internal server error, for (GET) [/read] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SQLTimeoutException: Timeout after 1001ms of waiting for a connection.]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
    at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
    at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
    at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)
    at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
    at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
    at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
    at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
Caused by: java.sql.SQLTimeoutException: Timeout after 1001ms of waiting for a connection.
    at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:227)
    at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93)
    at slick.jdbc.hikaricp.HikariCPJdbcDataSource.createConnection(HikariCPJdbcDataSource.scala:12)
    at slick.jdbc.JdbcBackend$BaseSession.conn$lzycompute(JdbcBackend.scala:415)
    at slick.jdbc.JdbcBackend$BaseSession.conn(JdbcBackend.scala:414)
    at slick.jdbc.JdbcBackend$SessionDef$class.prepareStatement(JdbcBackend.scala:297)
    at slick.jdbc.JdbcBackend$BaseSession.prepareStatement(JdbcBackend.scala:407)
    at slick.jdbc.StatementInvoker.results(StatementInvoker.scala:33)
    at slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:22)

控制器操作:

def readEquipment = Action.async { implicit request =>
    equipmentService.read map { eq => Ok(Json.toJson(eq)) }
  }

DAO方法:

override def read(): Future[Seq[Equipment]] =
    db.run(equipment.result)

似乎问题在于延迟初始化,它只在第一次请求数据库后启动。我该如何解决这个问题?

0 个答案:

没有答案