这个问题在这里已经有了答案:
8年前关闭。
Possible Duplicate:
How to run an arbitrary startup function in a ring project?
我正在使用 clojure ring 中间件和 compojure 来构建一个简单的 api。
我经常将应用程序部署为一场 war 。
这很好用,但我正在寻找在应用程序启动时运行一次性初始化代码的方法。当我运行“lein ring server”时,它运行得很好 - 但是,当作为 war 部署时,它似乎只在第一个请求到达服务器时运行(即懒惰)。有没有办法让它不懒惰(不使用 AOT) - 或者有没有更好的方法来 Hook 环中间件生命周期?
最佳答案
我认为您正在 lein-ring 插件中寻找 :init 参数。复制自 https://github.com/weavejester/lein-ring :
:init - A function to be called once before your handler starts. It should take no
arguments. If you've compiled your Ring application into a war-file, this function will
be called when your handler servlet is first initialized.
关于clojure - 部署后在 ring/compjure 应用程序启动时执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11099207/