sql-serverplayframeworkplayframework-2.3

How to set autoReconnect after configuration error in Play Framework?


I have an application on Play Framework 2.3, and connecting to SQL Server (2008, 2012 and 2014 versions). Configuration looks like this:

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

That works propperly except for application starting before starting SQL Server. In that case play generates an error:

Configuration error[Cannot connect to database [default]]

Is, that possible, to set PlayFramework automaticly reconnect, after that error, when Play arrives a new request, and how can I do that?


Solution

  • HikariCP has 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

    You can use play-hikaricp module to replace the default pool (BoneCP) and then configure HikariCP as explained above.