【问题标题】:Play 2 - External configuration file fails to load in production mode播放 2 - 外部配置文件无法在生产模式下加载
【发布时间】:2013-07-08 17:21:58
【问题描述】:

我在生产模式下的 play 2.1.1 应用程序的 application.conf 中包含外部文件时遇到问题(使用 start 启动时)

official documentation 之后,我在application.conf 中添加了include 语句:

[...]
include "/absolute/path/to/external/config/file.conf"

内容是这样加载的:

configuration.getConfig("some-key")

它在开发模式下工作正常,但在生产模式下失败(总是None)。

这使我无法将我的应用程序部署到生产环境中。

任何帮助/想法将不胜感激。

编辑: 根据 Saffron 的评论,我尝试了一些解决方法。

从包含语句中删除第一个斜杠不起作用。

通过 -Dconfig.file=/abs/path 加载配置文件会产生奇怪的结果,而且 Play 的行为似乎不一致:

play start -Dconfig.file=/path/to/file.conf 不起作用。但是启动 play THEN 运行 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

希望它可以帮助遇到同样问题的人。

【问题讨论】:

  • 我正在使用带有 Scala 的 Play 2.2。我在这里也面临同样的问题。我尝试按照 Play 文档 here 中的描述使用 -Dconfig.file,但它不起作用。我仍然收到配置错误。

标签: configuration playframework-2.0


【解决方案1】:

我的图像在 prod 模式下无法正确显示,但在 dev 模式下正常。 解决方案是将路径写为 ("images/...") 而不是 ("/images/...")。试试吧,只是为了科学。

无论如何,如果这不起作用,这里有一些关于 prod 模式下附加 Conf 的文档,其中包含用于覆盖文件的控制台行。 $ start -Dconfig.file=/opt/conf/prod.conf

http://www.playframework.com/documentation/2.0/ProductionConfiguration

【讨论】:

  • 抱歉我的回复晚了。不幸的是,您建议的两种解决方法都不能解决问题。我最终创建了一个新配置(请参阅我的编辑)。
猜你喜欢
  • 1970-01-01
  • 2014-06-01
  • 1970-01-01
  • 2023-02-02
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多