Play2“包括”指令覆盖配置替换 [英] Play2 "include" directive override configuration with substitution

查看:204
本文介绍了Play2“包括”指令覆盖配置替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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文件中具有覆盖属性。



推荐:
http://www.playframework.com/documentation/2.0/Configuration


如果未引用在键的开头包含后跟任何非单引号字符串,它是无效的,应该生成错误。



不允许替换,参数可能不是无引号字符串或任何其他类型的值。


尝试:


  1. 能够为另一个属性取代,但不能为包括像这样



    my.prop =override。$ {?application.mode}。conf



    override.dev.conf if application.mode = dev


  2. 如果我有下面的东西它不工作,我想它的预期的文档参考。



    includeoverride。$ {?application.mode}。conf



    覆盖在名为 override.dev.conf

  3. 的文件中的道具


问题:




  • 这应该是未来的增强功能还是预期的结果? li>
  • 实现我想要的其他方法是什么?



任何帮助将非常感激。

解决方案

我更喜欢覆盖 GlobalSettings.onLoadConfig 2013/05/23 / playframework-2-load-different-config-based-current-moderel =nofollow> PlayFramework 2根据当前模式加载不同的配置。它是在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

If an unquoted include at the start of a key is followed by anything other than a single quoted string, it is invalid and an error should be generated.

No substitutions are allowed, and the argument may not be an unquoted string or any other kind of value.

Tried:

  1. Able to get the substitution done for another property but not for include like this

    my.prop="override."${?application.mode}".conf"

    The above outputs to override.dev.conf if application.mode=dev

  2. 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“包括”指令覆盖配置替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆