2013-02-11 56 views
4

讀取網址我需要配置一些網址,我的Play應用程序,所以我說他們application.conf遊戲框架:無法從application.conf

application.url="http://www.mydomain.com" 
application.url.images="http://www.anotherdomain.com" 
application.url.images.logo="${application.url.images}/logo.png" 
... 

這裏下面我以我的觀點使用接入代碼上面的條目:

/home/j3d/Projects/test-app/conf/application.conf: 14-19: application.url.images.logo has type OBJECT rather than STRING 

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

<!DOCTYPE html> 

<html> 
    ... 

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

    ... 
</html> 

嗯...我,因爲每當我運行應用程序,我總是收到以下錯誤消息越來越瘋狂

有什麼想法?我錯過了什麼嗎?或者它是一個錯誤?

非常感謝。

回答

13

配置在Typesafe Configuration 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" 

等效於以下JSON:

{ 
    "application": { 
    "url": "http://example.com", 
    "images": { 
     "logo": "http://example.com/img/1.png", 
     "header": "http://example.com/img/3.png" 
    } 
    } 
} 

在你的榜樣,你首先指定字符串application.url,然後試圖鍵添加到它(在application.url.images關鍵url),喜歡它JSON對象,而不是字符串。在這種情況下,我不知道Typesafe Config的確切行爲,以及爲什麼在讀取配置文件時不立即引發錯誤。配置鍵的

嘗試重新安排層次,即:

application.url.prefix="http://www.mydomain.com" 
application.url.images.prefix="http://www.anotherdomain.com" 
application.url.images.logo="${application.url.images}/logo.png" 

這裏application.url將與鍵prefiximages對象,application.url.images將與鍵prefixlogo對象。

+1

謝謝...它的工作原理:-)請讓我指出$ {application.url.images}必須位於雙引號之外(即$ {application.url.images}「/ logo.png」)。 – j3d 2013-02-12 19:05:11