Playframework设置取决于环境 [英] Playframework settings depending on environment
问题描述
我正在使用playframework 2.1-RC2.首先,我已经所有 相似 问题,所以我遵循了按照每个环境分离application.conf文件的常见指示.因此,我有了application.test.conf,并以这种方式运行测试:
I'm using playframework 2.1-RC2. First of all I've seen all the similar questions, so I followed the common instruction of separating application.conf file per environment. So I have application.test.conf and I run tests this way:
play -Dconfig.file=./conf/application.test.conf "test"
我尝试了不同的组合,例如
I tried different combinations, like
play -Dconfig.file=./conf/application.test.conf ~test
或
play -Dconfig.file=conf/application.test.conf ~test
仍然没有运气,只是没有被选中,而是默认一个(application.conf).
Still no luck, it just does not get picked, default one (application.conf) is instead.
从另一面看,如果我这样做
From the other side, if I do
play -Dconfig.file=./conf/application.dev.conf "run"
然后应用程序选择正确的配置.
then application picks the right config.
那我该如何指定测试配置文件?
So how can I specify the test configuration file?
推荐答案
我发现以跨平台兼容的方式指定此功能的最可靠的方法是将其直接包含在Build.scala中:
I found the most robust way to specifiy this in a cross-platform compatible manner is to include it directly in the Build.scala:
val main = play.Project(appName, appVersion, appDependencies).settings(
javaOptions in Test += "-Dconfig.file=conf/test.conf",
...
)
奖金:配置一次,忘记;-)
Bonus: configure once and forget ;-)
这篇关于Playframework设置取决于环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!