configuration - Play 2 - 在生产模式下无法加载外部配置文件

标签 configuration playframework-2.0

我在 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/

相关文章:

java - 如何从 Eclipse 设置 java.library.path

windows-7 - Windows7 中的 Log4Net 本地主机寻址问题

grails - ASCII字符使用grails 3中的任意字符进行转换(附加)

java - Play 2.5 : get response body in custom http action

java - 保存期间检查 Play Framework 模型中更改的属性

configuration - 我可以让 Nginx 以不同的方式记录某些类型的请求吗?

windows - QT- 在 Windows 7 中安装

java - Play Framework (2.5) - JMX 端口可在 JVisualVM 中查看

java - Play Framework 2.1 (Java) eBean @Encrypted 注释错误

java - 如何在 Play! 中获取客户端的 IP 地址框架2.0?