configuration - 由于 "There is no started application"配置中断 Play 规范

标签 configuration playframework-2.0 specs2

我在 application.conf 上将一些字符串具体化到 HOCON .我正在访问这样的配置值:

import play.api.Play.current
import play.api.Play.configuration

configuration.getString("foo.bar").get()

尽可能早地在丢失 key 的情况下快速失败,就像文档说的那样。

现在我的一些依赖于配置对象的测试失败了,堆栈跟踪指出:
Caused by: java.lang.RuntimeException: There is no started application
我认为这与配置有关?我怎样才能解决这个问题? (测试是 specs2 )

最佳答案

你有没有 FakeApplication运行?如文件中所述:http://www.playframework.com/documentation/2.0/JavaTest在运行测试/测试方法之前?

来自维基的例子:

@Test
public void findById() {
   running(fakeApplication(), new Runnable() {
      public void run() {
        Computer macintosh = Computer.find.byId(21l);
        assertThat(macintosh.name).isEqualTo("Macintosh");
        assertThat(formatted(macintosh.introduced)).isEqualTo("1984-01-24");
       }
   });
}

如果这不能解决您的问题,也许从 Stacktrace 提供更多信息会有所帮助。

编辑:请仔细标记您的问题,提及 playframework 没有意义和 playframework-2.0

关于configuration - 由于 "There is no started application"配置中断 Play 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10853269/

相关文章:

PHP - 应用程序配置文件存储为 - ini、php、sql、cached、php 类、JSON、php 数组?

git - 与项目一起对依赖项进行版本控制

scala - 使用 specs2 和 FakeApplication() 测试数据库失败的进化插入

scala - 让测试仅在 SBT 控制台外工作

java - hadoop 多节点集群 - 从节点无法执行 mapreduce 任务

c# - ConfigurationErrorsException/SecurityException/FileIOPermission 在 NLog 实例化期间读取应用程序 .config 文件

java - 如何将字符串值数组从 Controller 传递到 View

unit-testing - 如何在specs2中定义DataTables的上下文

php - 如何用自定义 .ini 文件覆盖一些 PHP 配置默认值?

java - 使用 JavaWS 在表单数据中发布文件