简体   繁体   English

Play Framework:配置系统属性

[英]Play Framework: Configuring system properties

In play framework (2.2.1 & sbt 0.13) I have an IntegrationSpec that brings up a TestServer . 在Play框架(2.2.1&sbt 0.13)中,我有一个IntegrationSpec ,可以调出一个TestServer I need to be able to set SSL specific System Properties for the TestServer . 我需要能够为TestServer设置SSL特定的系统属性。 So far the only way I have been able to set it up correctly is passing them as command line properties like below 到目前为止,我能够正确设置它的唯一方法是将它们作为命令行属性传递,如下所示

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

I want the tests to run simply using play test . 我希望测试只使用play test运行。 For that in Build.scala I configured SBT javaOptions as follows 为了在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")

And in application.test.conf I set all the system properties. 在application.test.conf中,我设置了所有系统属性。 With this the TestServer is not even using application.test.conf . 有了这个, TestServer甚至没有使用application.test.conf I was not able to figure out why. 我无法弄清楚原因。 So I thought I will try the following: 所以我想我会尝试以下方法:

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

The TestServer did use application.test.conf but none of the system properties (javax.net.ssl.keyStore="..." etc.) configured in the file were being used. TestServer确实使用了application.test.conf但没有使用文件中配置的系统属性(javax.net.ssl.keyStore =“...”等)。

So I have two questions 所以我有两个问题

  1. How to have this running only using play test ? 如何只使用play test运行? . (I do not want to pass a long Map of properties to FakeApplication in TestServer ). (我不想在TestServer FakeApplication长属性Map传递给FakeApplication )。
  2. When I run play -Dconfig.file=conf/application.test.conf test , why are the system properties configured in application.test.conf not being used? 当我运行play -Dconfig.file=conf/application.test.conf test ,为什么application.test.conf配置的系统属性没有被使用?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM