springherokuenvironment-variablescleardb

Heroku - environment variable for Srping Boot DB connect


I have an app on Spring Boot that running in two environments, local and heroku:

  1. Local - connect to DB is configured by app.properties.

  2. Heroku - app is working w\o app.properties, using one environment variable:

    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

Question: how I can configure DB connect in Spring on local machine in same style, with one env variable?


Solution

  • 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:

    spring.datasource.url=${NAME_OF_THE_SYSTEM_VARIABLE}