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

99封情书 提交于 2019-12-13 03:06:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/55984799/deploy-spring-boot-app-to-heroku-with-a-particular-application-properties-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!