如何在环项目中运行任意启动功能? [英] How to run an arbitrary startup function in a ring project?

查看:113
本文介绍了如何在环项目中运行任意启动功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个compojure / ring应用程序,我现在运行 lein环服务器,我想编译为.war,所以我可以部署它。我有一个定义,但是,就像

I've got a compojure/ring application I currently run with lein ring server that I'd like to compile to a .war so I can deploy it. I've got a definition, however, just like

 (def foo (start-scheduler))

阻止编译和生成.war。为了避免这种情况,我想到了将调用移动到启动函数,但是当服务器启动时,我该如何调用它?

That blocks the compilation and the generation of the .war. To circumvent this, I thought about moving the call to a startup function, but how would I call it when the server launches?

如果我把调用放在处理程序中,我会遇到和以前一样的问题。

If I put the call inside the handler, I'd end up with the same problem as before.

感谢!

推荐答案

在您的 project.clj 处理程序还可以指定在应用程序启动时运行的init(和destroy)函数:

In your project.clj when declaring your Ring handler you can also specify an init (and destroy) function that is run when your application starts:

:ring {:init myproject.core/init
       :destroy myproject.core/destroy
       :handler myproject.core/handler}


b $ b

这里记录: https://github.com/weavejester/lein-ring#general -options

这篇关于如何在环项目中运行任意启动功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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