Jerry
Jerry

Reputation: 1197

MongoDB Connection for Spring Boot Application on Heroku

What is the best way to configure a Spring Boot application to connect to MongoDB on Heroku? I got it working specifying spring.data.mongodb.uri in the application.properties file, but I would like to set the connection up, so that I can keep the application pointing to my local MongoDB during development, while being able to push to Heroku without reconfiguring the connection URI each time.

Thanks, Jerry

Upvotes: 2

Views: 2693

Answers (2)

Zoltan Altfatter
Zoltan Altfatter

Reputation: 980

spring.data.mongodb.uri=${MONGOLAB_URI}

Upvotes: 1

Andy Wilkinson
Andy Wilkinson

Reputation: 116271

You could use profile-specific configuration to specify the URIs to use during development and when deploying to Heroku. A file named application-{profile}.properties will only be loaded when the matching profile is active, i.e. you could use a file named application-heroku.properties and enable the heroku profile when deploying to Heroku. Any profile-specific configuration will override the default configuration in application.properties. You can enable a profile using spring.profiles.active, for example:

java -jar your-app.jar --spring.profiles.active=heroku

Upvotes: 2

Related Questions