2

我正在尝试在 play framework 2.1 中的 application.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 文件中定义新键是一个好习惯吗?

谢谢。

4

3 回答 3

1

你必须使用冒号

gen.dn.port:"26017"

这是当前文档的链接

http://www.playframework.com/documentation/2.0.x/Configuration

于 2013-10-01T00:37:23.667 回答
1

将端口放在双引号之间:

gen.db.port="27017"
于 2013-07-10T19:09:38.370 回答
0

您可能使用错误的方法从配置中提取数据。我假设你像这样使用它:

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

但是此方法返回 play.api.Configuration 并期望对象位于路径“gen.db.port”下(如错误中所述)。由于在“gen.db.port”路径下您有一个数字,您应该将方法更改为:

current.configuration.getNumber("gen.db.port")
于 2013-12-15T09:14:49.463 回答