我在哪里将启动代码放在Play框架中? [英] Where do I put startup code in Play Framework?
本文介绍了我在哪里将启动代码放在Play框架中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在启动时运行一些代码来预缓存一些内容,并且还想启动一个Timer来在Web请求的关键路径之外重新缓存一些内容. Play框架有可能吗?我将代码放在哪里?
I want to run some code on startup to pre-cache some stuff, and would also like to start a Timer to re-cache some things outside the critical path of a web request. Is this possible with Play Framework, and where so I put this code?
推荐答案
您需要创建一个引导作业,该作业将在应用程序启动时由Play执行.
You need to create a bootstrap job which will be executed by Play at application start time.
@OnApplicationStart
public class Bootstrap extends Job {
public void doJob() {
//do stuff
}
}
在播放手册中详细了解如何执行此操作.
Read more about how to do this in the Play Manual.
这篇关于我在哪里将启动代码放在Play框架中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文