我正在開發多租戶Play Framework 2.1應用程序。我打算覆蓋GlobalSettings類的onRequest方法,以根據請求的子域加載和設置自定義配置。問題是,我不明白在Play 2.x中這是如何實現的。Play Framework 2.1:在全局設置中以編程方式覆蓋配置文件
我可以在啓動服務器時在命令行覆蓋系統屬性,但是如何在每個請求的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和獲取/設置緩存很容易,但我無法弄清楚如何通過編程設定一個新的配置玩框架2.1和文檔是這樣的事情有點光。
有什麼想法?任何人都知道一個更好,更有效的方法來做到這一點?
玩!使用TypeSafe配置庫。你可以看看它(可能會發現你在找什麼):https://github.com/typesafehub/config – 2013-03-31 14:09:02
我會看看,謝謝。 – 2013-04-04 00:11:03