在 Play Framework 中,我应该把启动代码放在哪里? [英] Where do I put startup code in Play Framework?

查看:27
本文介绍了在 Play Framework 中,我应该把启动代码放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在启动时运行一些代码来预缓存一些东西,还想启动一个计时器来重新缓存 web 请求的关键路径之外的一些东西.Play Framework 可以实现这一点吗?我把这段代码放在哪里了?

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 Framework 中,我应该把启动代码放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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