2016-03-08 54 views
0

我有一個使用Hikari連接池的項目。我爲所有數據庫逐個創建連接池,如new HikariDataSource(someConfig)如何防止Hikari池初始化失敗,如果數據庫連接失敗

當所有數據庫都可用時,此工作正常。但是,如果任何數據庫的離線播放項目給出了以下錯誤:

[RuntimeException: java.lang.ExceptionInInitializerError] 

我不希望應用程序崩潰,如果只是幾個數據庫處於脫機狀態。

如何避免崩潰應用程序出現此錯誤?

注意:我在另一個子項目中自己使用HikariCP包。我沒有使用play-hikari插件。

回答

3

設置hikaricp屬性initializationFailFast = false。其描述從hikaricp site

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