开发者

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

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.


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.


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜