A ServletContextListener implementation will meet your needs. If you do not want you to execute it yourself with :gen-class
, you can use the servlet utilities in the ring-java-servlet project.
To do this, create a file with the functions that you want to call during startup and / or shutdown:
(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)))
Then connect it to your webapp using the following web.xml
settings:
<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>
source share