Is there any way to substitute environment variables in playframework's application.conf?

后端 未结 3 1602
生来不讨喜
生来不讨喜 2021-02-05 15:30

Is there any way to use environment variables in the play! application.conf file? Something like this:

%prod.db.url=${env.DATABASE_JDBC_URL}
%prod.db.driver=org.         


        
相关标签:
3条回答
  • 2021-02-05 16:11

    ${ENV_VARIABLE_KEY} does resolve any variables that are set in your environment. you don't have to specify "env." prefix unless it's part of your key.

    0 讨论(0)
  • 2021-02-05 16:18

    I have the same problem. My solution :

    • let application.conf with only properties for local development and store it in a VCS (SVN, Git, ...) for your dev team
    • add a line in the application.conf file : "@include.prod=prod.conf"
    • the file prod.conf contains only %prod.* properties
    • create the file prod.conf directly on prod server (or store it in a different VCS than your application, where only allowed people can read/write it)

    It works fine for me.

    It just adds a message for the dev team when the application starts :

    ex: 20 mai 2011 21:09:16 play.Logger warn ATTENTION: Missing include: @include.prod

    Really not a problem. Just inform your dev team that this message is not a problem and to not delete the "@include.prod" line in application.conf

    Hope it helps

    0 讨论(0)
  • 2021-02-05 16:28

    All variables within ${} are resolved using the following sources:

    • ${application.path} equivalent to Play.applicationPath.getAbsolutePath()
    • ${play.path} equivalent to Play.frameworkPath.getAbsolutePath()
    • any other comes from System.getProperty.

    So you could add these as -Dkey=name parameters when launching Play! with your secret credentials specific to your environment.

    0 讨论(0)
提交回复
热议问题