Playframework 设置取决于环境 [英] Playframework settings depending on environment

查看:26
本文介绍了Playframework 设置取决于环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆