I have a servlet which is bundled as part of my application. I want to be able to configure Tomcat or Spring to load this servlet at boostrap before the application context is finally initialize.
I am doing this because - I am using the servlet to do some initial enviroment checking and file loading before the actual context gets fired.
Do anyone knows a good of doing this?
I have added servlet definition like this;
<servlet>
<servlet-name>init-class</servlet-name>
<servlet-class>package.initClass</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
This only gets fired after the app context has finished loading.
You need to place this initialization logic into ServletContextListener instead of servlet and declare it in web.xml as
<listener><listener-class>YourListenerClass</listener-class></listener>
Also, if your Spring context is loaded by ContextLoaderListener, your listener should be declared in web.xml before it, since listeners are fired in declaration order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With