lordneru
lordneru

Reputation: 770

Deploy Spring Boot app to Heroku with a particular application.properties file

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.

Upvotes: 8

Views: 4480

Answers (1)

Misantorp
Misantorp

Reputation: 2821

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

CLI

For setting the tst profile using the cli, try

$ heroku config:set SPRING_PROFILES_ACTIVE=tst

Dashboard

Navigate to the settings tab and set key as SPRING_PROFILES_ACTIVE and value as tst, then click save.

Platform API

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.

Upvotes: 23

Related Questions