如果无法访问mongo主机,则春季启动启动失败 [英] spring boot startup failure if mongo host not reachable

查看:68
本文介绍了如果无法访问mongo主机,则春季启动启动失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Spring boot mongo db应用程序,如果mongo主机还活着,当我开始运行此应用程序时,能够看到我的应用程序已启动并成功运行, 如果我的Mongo主机在我启动我的应用程序时关闭,则我的应用程序无法启动. 甚至没有想到,如果mongo主机关闭了,我的应用程序应该已经启动并正在运行.

I have Spring boot mongo db app, when i start running this application if mongo host is alive, am able to see the my app is up and running successfully, if my mongo host is down when i start my application my app failed to start. is there any way even thought if mongo host is down my application should be up and running.

有人可以帮我吗?

在我的应用程序中使用spring boot mongo属性

am using spring boot mongo properties in my application

spring.data.mongodb.repositories.enabled=true

spring.data.mongodb.port=27017

spring.data.mongodb.database=db

spring.data.mongodb.uri=mongodb://mongo-node-1.ballu/db

spring boot kafka也有同样的问题.

have same problem with spring boot kafka also.

推荐答案

对不起,上一条评论.无论如何,这是为了排除自动配置bean

Sorry for the previous comment. It was for excluding auto config beans, anyway

即使mongo主机关闭了我的应用程序,有什么办法 应该已经启动并运行了.

Is there any way even though if mongo host is down my application should be up and running.

是的, spring.datasource.continue-on-error=true #Whether to stop if an error occurs while initializing the database.

根据spring

默认情况下,Spring Boot启用Spring的故障快速功能 JDBC初始化程序.这意味着,如果脚本导致异常, 应用程序无法启动.您可以通过设置来调整该行为 spring.datasource.错误继续.

By default, Spring Boot enables the fail-fast feature of the Spring JDBC initializer. This means that, if the scripts cause exceptions, the application fails to start. You can tune that behavior by setting spring.datasource.continue-on-error.

从春季Kafka开始尝试此操作(我不确定这是否满足您的要求)

and as of spring kafka try this(i'm not sure if this meets your requirement)

spring.kafka.admin.fail-fast=true # Whether to fail fast if the broker is not available on startup.

这篇关于如果无法访问mongo主机,则春季启动启动失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆