问题描述
我的play2.1.0应用程序中有以下conf文件
- application.conf
- override.dev.conf
- override.qa.conf
- override.prod.conf
在application.conf文件中有一个 application.mode
属性,它将有一个dev / qa / prod值。
application.conf还有一行将env / mode特定的conf文件包含为覆盖。
原因:要在env / mode特定的conf文件中具有覆盖属性。
推荐:
尝试:
-
能够为另一个属性取代,但不能为
包括
像这样
my.prop =override。$ {?application.mode}。conf
到
override.dev.conf
ifapplication.mode = dev
-
如果我有下面的东西它不工作,我想它的预期的文档参考。
includeoverride。$ {?application.mode}。conf
覆盖在名为
override.dev.conf
的文件中的道具
问题:
- 这应该是未来的增强功能还是预期的结果? li>
- 实现我想要的其他方法是什么?
任何帮助将非常感激。
我更喜欢覆盖。它是在Scala中完成,但也应该可以在Java中做。
它可以以非常好的方式重载配置,而不需要启动应用程序命令行参数,您仍然使用播放
,播放开始
等启动应用程序。
如果您将 override.qa.conf
更改为 override.test,您应该能够使用此方法。 conf
所有共享设置
application.conf
,然后在其他选项中覆盖。
I have following conf files in my play2.1.0 application
- application.conf
- override.dev.conf
- override.qa.conf
- override.prod.conf
And there is a application.mode
property in the application.conf file which will have either one of dev/qa/prod values.
application.conf also has a line to include env/mode specific conf files as override. This is what is not working with substitution.
Reason:To have the override properties in the env/mode specific conf files.
Referred:http://www.playframework.com/documentation/2.0/Configuration
Tried:
Able to get the substitution done for another property but not for
include
like thismy.prop="override."${?application.mode}".conf"
The above outputs to
override.dev.conf
ifapplication.mode=dev
If I have something like below its not working and i suppose its what is expected as per the documentation reference.
include "override."${?application.mode}".conf"
Expected the above to include/override props in a file named
override.dev.conf
Question:
- Should this be a future enhancement or this is what is expected out of it?
- What are the other ways to implement what I wanted?
Any help would be really appreciated.
I prefer to override the GlobalSettings.onLoadConfig
as described in PlayFramework 2 load different config according to current mode. It is done in Scala but it should be possible to do in Java as well.
It lets you overload configurations in a very nice way without the need to start the application with command line arguments, you still start the app with play run
, play start
, etc.
You should be able to use this method if you change your override.qa.conf
to override.test.conf
since qa
is not a known mode in Play.
All shared settings in the application.conf
and then override in the other ones.
这篇关于Play2“包括”指令覆盖配置替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!