一个ServletContextListener实施将满足您的需求。如果您不想用:gen-class
自己实现一个,则可以在ring-java-servlet项目中使用servlet实用程序。
要做到这一点,创建启动和/或关机期间您是否愿意叫函数的文件:
(ns my.project.init
(:require [org.lpetit.ring.servlet.util :as util]))
(defn on-startup [context]
(do-stuff (util/context-params context)))
(defn on-shutdown [context]
(do-other-stuff (util/context-params context)))
然后通过以下web.xml
设置挂钩到你的web应用这样的:
<context-param>
<param-name>context-init</param-name>
<param-value>my.project.init/on-startup</param-value>
</context-param>
<context-param>
<param-name>context-destroy</param-name>
<param-value>my.project.init/on-shutdown</param-value>
</context-param>
<listener>
<listener-class>org.lpetit.ring.servlet.RingServletContextListener</listener-class>
</listener>
规范回答此:http://stackoverflow.com/questions/13978623/how-to-run-an-arbitrary-startup-function-in-a-ring-project –