问题
By default your Play application will be fully started (compiled, Global
's onStart
called, etc.) only after you do http request to it.
Is there a way to disable this lazy load and make Play app compile code and do startup once application process is run?
PS: I am using Play 2.3.
UPDATE: As Ryan pointed out lazy load happens only in dev. mode. Nevertheless I still need to disable it, despite this is relevant only to apps running in dev. mode.
回答1:
Lazy loading only applies in dev mode (play run
). Production mode is not lazy.
https://www.playframework.com/documentation/2.3.x/Production
回答2:
You can run your application with testProd
instead of run
(in the current 2.5 version). This starts your application in prod mode instead of dev.
If you're running from IntelliJ rather than the Play console, you need to create a new run config, choose SBT Task, and in the Tasks section enter testProd
.
回答3:
As Ryan explained it's for dev only.
TIP: IntelliJ Idea has a Play support, by default it opens the new browser window after running in dev mode, which initializes compilation automatically.
Quite sure you can do the same with simple shell script / batch file.
回答4:
play start
. This starts your app in production mode and loads onStart
when on the app start.
来源:https://stackoverflow.com/questions/26918545/disabling-lazy-load-in-play-application