scala - How to handle a 'Configuration error[Cannot connect to database [...]]' -


i implementing web service play framework, uses multiple databases. databases configured in conf/application.conf specifying db.database1..., db.database2... properties.

at startup, play try establish connections databases configured in database , if 1 connection fails, service not start.

in case, not databases necessary start web service, web service can still run limited functionality, if databases not available. since not databases under control, crucial web service handle connection error.

therefore question:

is there way either

  1. handle connection error overriding 'onerror' method or insert try-catch @ right place or
  2. manually create datasources @ runtime handle error when created

i prefer solution 2.

i using play version 2.4.2 scala version 2.11.7.

since whole exceptions fills multiple pages, insert first lines here:

creationexception: unable create injector, see following errors:  1) error in custom provider, configuration error: configuration error[cannot connect database [foo]]   while locating play.api.db.dbapiprovider   while locating play.api.db.dbapi     field @ play.api.db.nameddatabaseprovider.dbapi(dbmodule.scala:80)    while locating play.api.db.nameddatabaseprovider    @ com.google.inject.util.providers$guicifiedproviderwithdependencies.initialize(providers.java:149)    @ play.api.db.dbmodule$$anonfun$nameddatabasebindings$1.apply(dbmodule.scala:34):  binding(interface play.api.db.database qualified qualifierinstance(@play.db.nameddatabase(value=appstate)) 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 database [foo]]      @ play.api.configuration$.configerror(configuration.scala:178)     @ play.api.configuration.reporterror(configuration.scala:829)      @ play.api.db.defaultdbapi$$anonfun$connect$1.apply(defaultdbapi.scala:48)      @ play.api.db.defaultdbapi$$anonfun$connect$1.apply(defaultdbapi.scala:42)      @ scala.collection.immutable.list.foreach(list.scala:381)      @ play.api.db.defaultdbapi.connect(defaultdbapi.scala:42)      @ play.api.db.dbapiprovider.get$lzycompute(dbmodule.scala:72) 

i remember exists global settings configuration file catch errors when application starts.

take here: https://www.playframework.com/documentation/2.0/scalaglobal know using more recent play version more general idea how works.

in play 2.4.x file removed , uses di (https://www.playframework.com/documentation/2.4.x/globalsettings).


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -