ServletContextListenerの実装がニーズに応えます。で自分で実装したくない場合は、 ring-java-servletプロジェクト:gen-class
のサーブレット ユーティリティを使用できます。
これを行うには、起動および/またはシャットダウン中に呼び出したい関数を含むファイルを作成します。
(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
次に、次の設定を介してこれを webapp にフックします。
<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>