scala – 如何处理’配置错误[无法连接到数据库[…]]’
我正在使用Play Framework实现一个使用多个数据库的Web服务.通过指定db.
database1 …,db.database2 …属性,在conf / application.conf中配置所有数据库.
在启动时,play将尝试建立与数据库中配置的所有数据库的连接,如果一个连接失败,则服务将无法启动. 在我的情况下,并非所有数据库都是启动Web服务所必需的,但如果某些数据库不可用,则Web服务仍然可以使用有限的功能运行.由于并非所有数据库都在我的控制之下,因此我的Web服务处理连接错误至关重要. 因此我的问题是: 还有办法吗? >通过覆盖某些’onError’方法来处理连接错误,或者在正确的地方插入try-catch或 我更喜欢解决方案2. 我使用scala版本2.11.7的播放版本2.4.2. 由于整个异常填充多个页面,我只在这里插入第一行: 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) 解决方法
我记得存在一个全局设置配置文件,用于在应用程序启动时捕获错误.
看看这里:https://www.playframework.com/documentation/2.0/ScalaGlobal我知道你正在使用更新的游戏版本,但你会更全面地了解它是如何工作的. 在播放2.4.x中,此文件已被删除并立即使用DI(https://www.playframework.com/documentation/2.4.x/GlobalSettings). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |