我在 application.conf
中包含外部文件时遇到问题我在生产模式下的 play 2.1.1 应用程序(使用 start
启动时)
关注 official documentation我添加了一个 include
我的声明 application.conf
:
[...]
include "/absolute/path/to/external/config/file.conf"
内容以这种方式加载:
configuration.getConfig("some-key")
它在开发模式下工作正常,但在生产模式下失败(总是
None
)。这阻止了我将应用程序部署到生产中。
任何帮助/想法将不胜感激。
编辑:
在 Saffron 的评论之后,我尝试了一些解决方法。
从 include 语句中删除第一个斜杠不起作用。
通过 -Dconfig.file=/abs/path 加载配置文件给出了奇怪的结果,似乎 Play 的行为方式不一致:
play start -Dconfig.file=/path/to/file.conf
不起作用。然而启动play
然后运行 start -Dconfig.file=/path/to/file.conf
有用吗??!!所以我最终创建了一个新的配置而不是使用 Play 的:
val conf = ConfigFactory.parseFile(new File("/path/to/file.conf")).resolve()
val myValues = new Configuration(conf).getConfig("some-key").get
希望它可以帮助遇到同样问题的人。
最佳答案
我有一个问题,我的图像在 prod 模式下无法正确显示,但在 dev 模式下没问题。
解决方案是将路径写为 ("images/...") 而不是 ("/images/...")。试试吧,只是为了科学。
无论如何,如果这不起作用,这里有一些关于 prod 模式下附加 Conf 的文档,带有控制台行来覆盖文件。 $ start -Dconfig.file=/opt/conf/prod.conf
http://www.playframework.com/documentation/2.0/ProductionConfiguration
关于configuration - Play 2 - 在生产模式下无法加载外部配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17532491/