Is there any way to substitute environment variabl

2019-03-15 05:47发布

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.postgresql.Driver
%prod.jpa.ddl=validate

I don't want to hardcode the URL in my application.conf because it contains credentials that the developer should not have access to.

3条回答
混吃等死
2楼-- · 2019-03-15 06:10

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.

查看更多
Evening l夕情丶
3楼-- · 2019-03-15 06:10

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

查看更多
你好瞎i
4楼-- · 2019-03-15 06:14

${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.

查看更多
登录 后发表回答