0

I am using mongodb in my spring boot application with below configuration.

spring:
  data:
    mongodb:
      authentication-database: admin
      database: log
      username: ${MONGO_DATASOURCE_USERNAME}
      password: ${MONGO_DATASOURCE_PASSWORD}

When my mongodb is up and running, Everything works fine.

But when i deploy this on Jenkins (Where mongodb is not installed), I have observed weird behaviour that my spring application is trying to connect mongodb at every second which makes my app startup time huge.

Similar scenario i have with my Postgres database as well (No postgres on Jenkins, Still my application should start without failing), But in that i am able to skip the postgres or start the app even though we have error with postgres by using constinue-on-error: true property in my yaml's datasource tag file.

Is there anything that i can do for mongodb?

My spring boot application should start even though we don't have mongodb.

I tried below code but it didn't worked.

@SpringBootApplication(exclude = {
    MongoAutoConfiguration.class,
    MongoDataAutoConfiguration.class
})

Thanks!

Jayesh Dhandha
  • 1,983
  • 28
  • 50
  • Here is a similar issue with various solutions: [Disable all Database related auto configuration in Spring Boot](https://stackoverflow.com/questions/36387265/disable-all-database-related-auto-configuration-in-spring-boot) – prasad_ Jun 24 '20 at 10:45
  • @prasad_ I tried the given suggestion, But no luck. `Unable to close ApplicationContext` and my app is not starting now :( – Jayesh Dhandha Jun 24 '20 at 11:13

1 Answers1

-1

You can use @Profile (https://docs.spring.io/spring/docs/5.2.7.RELEASE/spring-framework-reference/core.html#beans-definition-profiles-java) to create different configuration based on running profile (stage, production, test). you can set spring profile with environment variable spring.profiles.active

  • We already have this configured, But as i said `i want to keep this configuration` and just wanted to make sure my `spring boot starts without being failed even though mongodb is not there`, I wanted to implement `lazy-loading` kind of stuff. – Jayesh Dhandha Jun 24 '20 at 09:34