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!
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.