Playframework 如何管理游戏中不同环境的配置属性

Playframework 如何管理游戏中不同环境的配置属性,playframework,Playframework,在Play Framework中,我注意到可以分离在开发或生产模式中使用的配置属性 最佳使用示例是baseUrl: # Url-resolving in Jobs # ~~~~~~ # When rendering templates with reverse-url-resoling (@@{..}) in Jobs (which do not have an inbound Http.Request), # ie if sending a HtmlMail, Play need to kno

在Play Framework中,我注意到可以分离在开发或生产模式中使用的配置属性

最佳使用示例是baseUrl:

# Url-resolving in Jobs
# ~~~~~~
# When rendering templates with reverse-url-resoling (@@{..}) in Jobs (which do not have an inbound Http.Request),
# ie if sending a HtmlMail, Play need to know which url your users use when accessing your app.
# %test.application.baseUrl=http://localhost:9000/

%dev.application.baseUrl=http://127.0.0.1:9000
%prod.application.baseUrl=http://www.example.com
但我不能让它为另一个财产工作:

%dev.application.staticUrl=/public
%prod.application.staticUrl=http://static.example.com
调用
Play.configuration.getProperty(“application.staticUrl”)
,甚至调用
Play.configuration.getProperty(“%dev.application.staticUrl”)
(要测试),都不会导致:/


我如何才能做到这一点?

在开发模式下运行时,您不需要在行前面加上开发代码

开发应用程序时,我在开发模式下运行我的应用程序,并在prod模式下运行2个实例。 my application.conf的示例:


application.mode=dev
%inst1.application.mode=prod
%inst2.application.mode=prod
mail.smtp=mock
%inst1.mail.smtp=MAILSERVER1
%inst2.mail.smtp=MAILSERVER1

使用play run myapp运行应用程序将使用不带前缀的属性。 在prod模式下,我使用播放开始--%inst1播放开始--%inst2运行2个实例

这将创建2个应用程序实例,运行时使用它们自己的属性,如果未指定,则使用默认属性

使用getProperty时,切勿使用前缀,即Play.configuration.getProperty(“mail.smtp”)将在开发模式下返回mock,在生产模式下返回MAILSERVER1。


在您的例子中,有两种配置(不要与运行模式混淆!),dev和prod。应用程序运行模式由application.mode属性定义。

我喜欢您的答案,但只是一个问题。这是否意味着我必须定义application.staticUrl&%prod.application.staticUrl?(或者我误解了什么)?很好,事实上,我从来不知道这在游戏中是可能的,你让我发现了这一点。谢谢!!:)我投了赞成票并接受了你的答案。添加一个修改以反映答案适用于Play 1.x会很有用。我已经更改了标题,但这可能还不够,并且在应用2.x时会造成麻烦。这件事发生在我身上。

application.mode=dev
%inst1.application.mode=prod
%inst2.application.mode=prod
mail.smtp=mock
%inst1.mail.smtp=MAILSERVER1
%inst2.mail.smtp=MAILSERVER1