2013-07-10 30 views
2

我試圖在play Framework 2.1中的application.conf文件中添加新的鍵。我已經添加下面的鍵:在播放框架應用程序conf文件中定義鍵

gen.db.host=localhost 
gen.db.port=27017 
gen.db.name=test 

當我開始我的應用程序,它拋出以下錯誤:

Configuration error: Configuration error[application.conf: 46: port has type NUMBER rather than OBJECT] 
...... 
...... 
...... 
Caused by: com.typesafe.config.ConfigException$WrongType: application.conf: 46: port has type NUMBER rather than OBJECT 

我不明白這個問題。我該如何解決它?另外,在application.conf文件中定義新的密鑰是否是一種好的做法?

謝謝。

回答

1

把端口雙引號之間:

gen.db.port="27017" 
+0

它被扔配置錯誤:配置錯誤[application.conf:46:端口的類型是STRING而不是OBJECT] – popcoder

+0

請添加從配置文件中讀取的代碼。 –

0

你正在使用錯誤的方法od從配置中提取數據。我假設你使用它像:

current.configuration.getConfig("gen.db.port") 

但是這個方法返回play.api.Configuration,預計目標是在路徑「gen.db.port」(因爲它是在錯誤中提到)。既然你有許多的「gen.db.port」路徑下,你應該改變方法:我已經試過了

current.configuration.getNumber("gen.db.port") 
相關問題