【发布时间】:2013-10-04 23:21:14
【问题描述】:
我正在开发一个多租户 Play Framework 2.1 应用程序。我打算重写 GlobalSettings 类的 onRequest 方法,以根据请求的子域加载和设置自定义配置。问题是,我看不出这在 Play 2.x 中是如何实现的。
我可以在启动服务器时在命令行中覆盖系统属性,但是如何在 Java 代码中为每个请求以编程方式执行此操作?
代码看起来像这样(我假设):
@Override
public play.mvc.Action onRequest(Request request, Method actionMethod) {
//Look up configuration settings in Cache based on request subdomain
//(i.e. Cache.get("subdomain.conf"))
//if not in cache:
//load appropriate configuration file for this subdomain (java.io.File)
//set new configuration from file for this request
//cache the configuration for future use in a new thread
//else
//set configuration from cache for this request
return super.onRequest(request, actionMethod);
}
}
查找 URL 和获取/设置缓存很容易,但我不知道如何以编程方式为 Play Framework 2.1 设置新配置,并且文档对此类内容略知一二。
有什么想法吗?有人知道更好、更有效的方法吗?
【问题讨论】:
-
玩!使用 TypeSafe 配置库。你可以看看它(并且可能会找到你要找的东西):github.com/typesafehub/config
-
我去看看,谢谢。
标签: java playframework playframework-2.1