SQLTimeOutException 与 slickpg 和 playframework

SQLTimeOutException with slickpg and playframework

麻烦了,不知道为什么连不上数据库,一切正常

play.api.http.HttpErrorHandlerExceptions$$anon: Execution exception[[SQLTimeoutException: Timeout after 60001ms of waiting for a connection.]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
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:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$$anonfun$apply.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$$anonfun$apply.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:345)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)

Caused by: java.sql.SQLTimeoutException: Timeout after 60001ms 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)

Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not   supported, connection test query must be configured

at  com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
at com.zaxxer.hikari.pool.BaseHikariPool.run(BaseHikariPool.java:413)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
... 3 common frames omitted

我的application.conf

slick.dbs.default.db.connectionTimeout=60000
slick.dbs.default.driver="utils.db.TetraoPostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="jdbc:postgresql://localhost:5432 /templatesite_db"
slick.dbs.default.db.user="marcus"
slick.dbs.default.db.password="123"
play.http.parser.maxDiskBuffer=100MB
parsers.anyContent.maxLength=100MB

build.sbt

lazy val root = (project in file("."))
.settings(commonSettings: _*)
.settings(routesGenerator := InjectedRoutesGenerator)
.settings(
    libraryDependencies += "com.typesafe.slick" %% "slick" % "3.1.1",
    libraryDependencies += "com.typesafe.slick" %% "slick-codegen" % "3.1.1",
    libraryDependencies += "com.github.tminglei" %% "slick-pg" % "0.14.1",
    libraryDependencies += "com.github.tminglei" %% "slick-pg_date2" % "0.14.1",
    libraryDependencies += "com.typesafe.play" %% "play-slick" % "2.0.2",
    libraryDependencies += "jp.t2v" %% "play2-auth" % "0.14.2",
    libraryDependencies += play.sbt.Play.autoImport.cache,
    libraryDependencies += "com.github.t3hnar" %% "scala-bcrypt" % "2.6",
    libraryDependencies += "org.webjars" %% "webjars-play" % "2.5.0",
    libraryDependencies += "org.webjars" % "foundation" % "6.2.3"
).enablePlugins(PlayScala)
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

我认为可能是 HikariCP 模块正在寻找 connectionTestQuery 但没有找到(并抛出错误)。尝试将以下内容添加到 application.conf:

slick.dbs.default.db.connectionTestQuery="/*ping*/ select 1" // or whatever

答案来自: