简体   繁体   English

Heroku - Srping Boot DB 连接的环境变量

[英]Heroku - environment variable for Srping Boot DB connect

I have an app on Spring Boot that running in two environments, local and heroku:我在 Spring Boot 上有一个应用程序,它在本地和 heroku 两个环境中运行:

  1. Local - connect to DB is configured by app.properties.本地 - 连接到数据库由 app.properties 配置。

  2. Heroku - app is working w\o app.properties, using one environment variable: Heroku - 应用程序正在 w\o app.properties 工作,使用一个环境变量:

    heroku config -a zed-social-network === zed-social-network Config Vars CLEARDB_DATABASE_URL: mysql://{login}:{pass}@host.com/heroku?reconnect=true&useUnicode=true&characterEncoding=UTF-8 heroku config -a zed-social-network === zed-social-network 配置变量 CLEARDB_DATABASE_URL: mysql://{login}:{pass}@host.com/heroku?reconnect=true&useUnicode=true&characterEncoding=UTF-8

Question: how I can configure DB connect in Spring on local machine in same style, with one env variable?问题:如何在本地机器上以相同的样式配置 Spring 中的 DB 连接,并使用一个 env 变量?

I would use a command line argument:我会使用命令行参数:

mvn spring-boot:run -Drun.arguments=--customArgument=custom

so in your case所以在你的情况下

mvn spring-boot:run -Drun.arguments=--CLEARDB_DATABASE_URL=your_url

-- --

Alternatively, you could add the url to system variables and then reference it in application.properties like so:或者,您可以将 url 添加到系统变量中,然后在 application.properties 中引用它,如下所示:

spring.datasource.url=${NAME_OF_THE_SYSTEM_VARIABLE}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM