自定义配置文件 - 播放!框架2.0 [英] Custom configuration files - Play! Framework 2.0

查看:185
本文介绍了自定义配置文件 - 播放!框架2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于从自定义配置文件加载属性的问题。我已经尝试了
两种不同的方法来加载我的 oauth.properties 文件,但我不能
要么工作所以我希望有人来这里可以帮助我。

I have a question about loading properties from custom configuration files. I have tried two different approaches to loading my oauth.properties file but I can't get either to work so I'm hoping someone here can help me.

我尝试的第一种方法是将文件添加到conf目录
并因此引用它:

The first approach I tried was to add the file to the conf directory and reference it thusly:

String oauthPropertiesFile = ClassLoader.getSystemResource("oauth.properties").getFile();

但刚刚返回 NULL

我尝试的第二种方法是添加:

The second approach I tries was to add:

@include.oauthProperties = oauth.properties

application.conf 文件然后在
中引用它我的控制器如:

to the application.conf file and then reference it in my controller like:

String clientId = oauthProperties.clientId;

但是这不能编译。

有人能说清楚我在这里做错了吗?

Can anyone shed some light on what I'm doing wrong here?

推荐答案

我不确定conf是否属于类路径。所以我会尝试 /conf/oauth.properties 或将文件放入类路径中。此外,您应该使用 Play.application.classloader()而不是Classloader。

I'm not sure if conf is part of the classpath. So I would try /conf/oauth.properties or put the file into the classpath. Furthermore you should use Play.application.classloader() instead of Classloader.

关于包含:我仍然认为你需要调用 Play.application()。configuration()。get(clientID);

About the include: I still think you need to call Play.application().configuration().get("clientID");

To分析您可以使用 -Dconfig.trace = loads 启动应用程序的情况,并使用 Play.application()。configuration()分析配置.root ()。render()

To analyze the situation you can start the app with -Dconfig.trace=loads and analyse the configuration with Play.application().configuration().root().render().

希望这能为您提供足够的提示,以便您解决问题。

Hope this give you enough hints so that you can solve your problem.

这篇关于自定义配置文件 - 播放!框架2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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