I am implementing a web service with a Play Framework that uses multiple databases. All databases are configured in conf / application.conf by setting the properties db.database1 ..., db.database2 ....
When starting, playback will try to establish connections with all the databases configured in the database, and if one connection fails, the service will not start.
In my case, not all databases are needed to run the web service, but the web service may work with limited functionality if some databases are not available. Since not all databases are under my control, it is very important for my web service to handle a connection error.
So my question is:
Is there any way either
- handle a connection error by overriding some onError method or by inserting try-catch in the right place or
- Manually create data sources at run time to handle errors when they are created.
I would prefer solution 2.
I am using game version 2.4.2 with scala version 2.11.7.
Since all exceptions fill several pages, I only insert the first lines:
CreationException: Unable to create injector, see the following errors:
1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [foo]]
while locating play.api.db.DBApiProvider
while locating play.api.db.DBApi
for field at play.api.db.NamedDatabaseProvider.dbApi(DBModule.scala:80)
while locating play.api.db.NamedDatabaseProvider
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at play.api.db.DBModule$$anonfun$namedDatabaseBindings$1.apply(DBModule.scala:34):
Binding(interface play.api.db.Database qualified with QualifierInstance(@play.db.NamedDatabase(value=appstate)) to ProviderTarget(play.api.db.NamedDatabaseProvider@1a7884c6)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
Caused by: Configuration error: Configuration error[Cannot connect to database [foo]]
at play.api.Configuration$.configError(Configuration.scala:178)
at play.api.Configuration.reportError(Configuration.scala:829)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48)
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
at scala.collection.immutable.List.foreach(List.scala:381)
at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
source
share