clojure - 部署后在 ring/compjure 应用程序启动时执行函数

标签 clojure compojure ring

这个问题在这里已经有了答案:




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/

相关文章:

function - 关于一个函数如何在 clojurescript 中生成另一个函数的文档?

clojure - 尝试动态创建 map

post - 无法在 Clojure 中完成 POST 请求

json - 用于 Clojure Web 开发的 ring-json 与 cheshire

testing - 使用 ring-mock 将数据传递到 midje 测试中的解放者后端点

clojure - clojure/ring 中的 servlet 集成安全性?

clojure - Elixir 是否具有类似于 Clojure 的持久数据结构?

具有相互依赖值的 HashMap 的 clojure 规范?

clojure - 解构形式和组合?

clojure - ring-json 的 wrap-json-response 中间件和 compojure 返回文本/纯文本?