Play Framework配置错误后如何设置autoReconnect?

How to set autoReconnect after configuration error in Play Framework?

我在 Play Framework 2.3 上有一个应用程序,并连接到 SQL 服务器(2008、2012 和 2014 版本)。配置如下所示:

db.default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.default.url="jdbc:sqlserver://192.168.100.101;databaseName=myDatabase;SelectMethod=direct;autoReconnect=true"

除应用程序在启动 SQL 服务器之前启动外,一切正常。在这种情况下,播放会产生错误:

Configuration error[Cannot connect to database [default]]

是否可以设置 PlayFramework 在出现错误后自动重新连接,当 Play 收到新请求时,我该怎么做?

HikariCP 有 a property to do exactly what you want:

initializationFailFast: This property controls whether the pool will "fail fast" if the pool cannot be seeded with initial connections successfully. If you want your application to start even when the database is down/unavailable, set this property to false. Default: true

您可以使用 play-hikaricp module 替换默认池 (BoneCP),然后按照上述说明配置 HikariCP。