【问题标题】:Play Framework: Configuring system propertiesPlay Framework:配置系统属性
【发布时间】:2014-03-11 00:52:45
【问题描述】:

在游戏框架(2.2.1 & sbt 0.13)我有一个IntegrationSpec,它带来了一个TestServer。我需要能够为TestServer 设置 SSL 特定的系统属性。到目前为止,我能够正确设置它的唯一方法是将它们作为命令行属性传递,如下所示

play -Djavax.net.ssl.keyStore=... -Djavax.net.ssl.keyStorePassword=.... -D... test

我希望仅使用 play test 运行测试。为此,我在 Build.scala 中配置了 SBT javaOptions 如下

val main = play.Project(appName, appVersion, appDependencies).settings(
    Keys.fork in Test := false,
    javaOptions in Test += "-Dconfig.file=conf/application.test.conf")

我在 application.test.conf 中设置了所有系统属性。有了这个TestServer 甚至没有使用application.test.conf。我无法弄清楚为什么。所以我想我会尝试以下方法:

play -Dconfig.file=conf/application.test.conf test

TestServer 确实使用了application.test.conf,但没有使用文件中配置的系统属性(javax.net.ssl.keyStore="..." 等)。

所以我有两个问题

  1. 如何仅使用play test 运行此程序? . (我不想在TestServer 中将很长的属性映射传递给FakeApplication)。
  2. 运行play -Dconfig.file=conf/application.test.conf test时,为什么application.test.conf中配置的系统属性没有被使用?

【问题讨论】:

  • 我也遇到了同样的问题,你用.conf文件找到解决方法了吗?

标签: scala playframework sbt


【解决方案1】:

我不确定这是否适用于设置读取配置文件的属性,但您可以使用 System.setProperty 设置您的个人属性,如下所示:

System.setProperty("application.secret","psssst!")

【讨论】:

    猜你喜欢
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多