1

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.

could someone please help me on this?

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

have same problem with spring boot kafka also.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Use this to exclude spring boot for auto configuring mongodb @SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class}) – Clover Feb 11 '19 at 05:11

1 Answers1

-1

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

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

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

as per spring doc

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.

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.
Clover
  • 507
  • 7
  • 22