使用特定的application.properties文件将Spring Boot应用程序部署到Heroku [英] Deploy Spring Boot app to Heroku with a particular application.properties file
问题描述
我想为每个环境定义不同的 application.properties
文件。
在本地工作时,我想定义一个H2数据库。对于测试环境(Heroku),我有一个MySQL数据库配置。因此,我想为这种工作情况定义完全不同的文件。
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.
当前,我在本地有 application.properties
porpouse和 application-tst.properties
在Heroku中使用。但是我不知道如何在部署时选择合适的。
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.
我的目标是为在Heroku中运行的应用配置与在本地运行的应用不同的配置
My goal is to have different configuration for my app running in Heroku than the one running in my local machine.
推荐答案
您可以使用 spring.profiles.active $控制哪个配置文件处于活动状态。 c $ c>属性(文档)。在Heroku上,您可以通过 cli,仪表板或平台API
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设置 tst
配置文件,请尝试
For setting the tst
profile using the cli, try
$ heroku config:set SPRING_PROFILES_ACTIVE=tst
仪表板
导航至设置
选项卡,并将键设置为 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"
请注意,尽管设置了 spring.profiles.active
属性作为配置变量将影响整个应用程序。
Be aware though that setting the spring.profiles.active
property as a config var will affect the whole application.
这篇关于使用特定的application.properties文件将Spring Boot应用程序部署到Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!