Play Framework:无法从application.conf读取URL

j3d*_*j3d 4 playframework playframework-2.0

我需要为Play应用程序配置一些URL,所以我将它们添加到application.conf:

application.url="http://www.mydomain.com"
application.url.images="http://www.anotherdomain.com"
application.url.images.logo="${application.url.images}/logo.png"
...
Run Code Online (Sandbox Code Playgroud)

以下是我在视图中用于访问上述条目的代码:

@(title: String)
@import play.api.Play.current

<!DOCTYPE html>

<html>
    ...

    <img src="@{ currrent.configuration.getString("application.url.images.logo") }" />

    ...
</html>
Run Code Online (Sandbox Code Playgroud)

嗯...我疯了,因为每当我运行应用程序时,我总是收到以下错误消息:

/home/j3d/Projects/test-app/conf/application.conf: 14-19: application.url.images.logo has type OBJECT rather than STRING
Run Code Online (Sandbox Code Playgroud)

任何的想法?我错过了什么吗?或者这是一个错误?

非常感谢你.

kol*_*len 13

Type中的Configfe Play中使用的配置库表示类似JSON的结构.点表示法是用于创建嵌套对象的语法糖({ ... }在JSON中).例如:

application.url="http://example.com"
application.images.logo="http://example.com/img/1.png"
application.images.header="http://example.com/img/3.png"
Run Code Online (Sandbox Code Playgroud)

相当于以下JSON:

{
  "application": {
    "url": "http://example.com",
    "images": {
      "logo": "http://example.com/img/1.png",
      "header": "http://example.com/img/3.png"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在您的例子中,你首先指定字符串application.url,然后试图键添加到它(重点urlapplication.url.images),喜欢它是JSON对象,而不是字符串.在这种情况下,我不知道Typesafe配置的确切行为,以及为什么它在读取配置文件时不会立即引发错误.

尝试重新排列配置键的层次结构,即:

application.url.prefix="http://www.mydomain.com"
application.url.images.prefix="http://www.anotherdomain.com"
application.url.images.logo="${application.url.images}/logo.png"
Run Code Online (Sandbox Code Playgroud)

这里application.url将与键对象prefiximages,以及application.url.images将与键来反对prefixlogo.