I want to define different application.properties
file for each environment.
When working locally, I want to define a H2 database. For test environment (Heroku) I have a MySQL database configuration. Thus, I want to define completly different files for such working cases.
Currently I have application.properties
for local porpouse, and application-tst.properties
to be use in Heroku. But I don't know how to pick the proper one when deploying.
My goal is to have different configuration for my app running in Heroku than the one running in my local machine.
The Spring Boot model of deploying standalone applications is a great fit for Heroku. You can use either Maven or Gradle to deploy a Spring application on Heroku, but for this guide we'll assume that you're using Maven and have Maven 3 installed on your machine. To begin, create a free Heroku account.
You can control which profile is active using the spring.profiles.active
property (documentation). On Heroku you can set this using config vars either via the cli, the dashboard or the platform API
For setting the tst
profile using the cli, try
$ heroku config:set SPRING_PROFILES_ACTIVE=tst
Navigate to the settings
tab and set key as SPRING_PROFILES_ACTIVE
and value as tst
, then click save
.
You could use several tools to achieve the same result, but following the Platform API documentation, you could use curl
$ curl -n -X PATCH https://api.heroku.com/apps/$APP_ID_OR_NAME/config-vars \
-d '{ "SPRING_PROFILES_ACTIVE": "tst" }' \
-H "Content-Type: application/json" \
-H "Accept: application/vnd.heroku+json; version=3"
Be aware though that setting the spring.profiles.active
property as a config var will affect the whole application.
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