Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 596
lordneru Avatar asked May 04 '19 16:05

lordneru


People also ask

Can I deploy spring boot application to Heroku?

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.


1 Answers

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.

like image 175
Misantorp Avatar answered Sep 30 '22 19:09

Misantorp