I'm new to Spring Boot and am trying to configure a connection to MongoDB using environment variables - i.e. I have followed an example online showing how to configure my mongo database/host/port via application.properties, but I want my configuration to come from environment variables - what is the best approach to do this? Thanks
After some digging, I've managed to get it working by using an application.properties file, but specifying the env variable names within the file, e.g.
spring.data.mongodb.database = ${SPRING_DATA_MONGODB_DATABASE}
spring.data.mongodb.host = ${SPRING_DATA_MONGODB_HOST}
spring.data.mongodb.port = ${SPRING_DATA_MONGODB_PORT}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With