部署后在ring/compjure应用程序启动时执行功能

Mic*_*ale 6 clojure compojure ring

可能重复:
如何在环项目中运行任意启动功能?

我正在使用clojure环中间件,使用compojure来构建一个简单的api.我经常将应用程序部署为战争.

这很好用,但我正在寻找在应用启动时运行一次初始化代码的方法.当我运行"lein ring server"时它运行得很好 - 但是,当部署为战争时,它似乎只在第一个请求命中服务器时运行(即懒惰).有没有办法让它不是懒惰(不使用AOT) - 或者是否有更好的方法来挂钩环中间件生命周期?

Dan*_*ero 2

我认为您正在 lein-ring 插件中寻找 :init param 。复制自 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.
Run Code Online (Sandbox Code Playgroud)