我使用Akka Scheduler每分钟向我的Play Framework应用程序的根URL发出请求,以刷新应用程序的缓存(如果它到期)。
当我在我的localhost上工作时,我正在调用WS.url("http://127.0.0.1:9000/").get();
。显然,当我推向生产时,我会更改它以请求生产URL。
是否有自动获取根网址的功能,这样我每次都不需要更改它?
答案 0 :(得分:2)
你有3个解决方案,从反向路由或从配置或从两个(具有配置优先级)获取它:
String reverseRoute = routes.Application.index().absoluteURL(request());
String refreshUrlFromConf = Play.application().configuration().getString("refreshUrl");
String mixed = Play.application().configuration().getString(
"refreshUrl",
routes.Application.index().absoluteURL(request())
);
如果您想使用配置方法,当然需要将其添加到application.conf
:
refreshUrl = "http://your-instance.tld"
顺便说一下,你不需要自己刷新缓存,它会在第一次请求后刷新,在缓存终止后立即刷新。