public class WebAppRootListener extends Object implements ServletContextListener
Can be used for toolkits that support substitution with system properties (i.e. System.getProperty values), like log4j's "${key}" syntax within log file locations.
Note: This listener should be placed before ContextLoaderListener in web.xml
,
at least when used for log4j. Log4jConfigListener sets the system property
implicitly, so there's no need for this listener in addition to it.
WARNING: Some containers, e.g. Tomcat, do NOT keep system properties separate per web app. You have to use unique "webAppRootKey" context-params per web app then, to avoid clashes. Other containers like Resin do isolate each web app's system properties: Here you can use the default key (i.e. no "webAppRootKey" context-param at all) without worrying.
WARNING: The WAR file containing the web application needs to be expanded to allow for setting the web app root system property. This is by default not the case when a WAR file gets deployed to WebLogic, for example. Do not use this listener in such an environment!
WebUtils.setWebAppRootSystemProperty(javax.servlet.ServletContext)
,
System.getProperty(java.lang.String)
Constructor and Description |
---|
WebAppRootListener() |
Modifier and Type | Method and Description |
---|---|
void |
contextDestroyed(ServletContextEvent event)
Receives notification that the ServletContext is about to be
shut down.
|
void |
contextInitialized(ServletContextEvent event)
Receives notification that the web application initialization
process is starting.
|
public void contextInitialized(ServletContextEvent event)
javax.servlet.ServletContextListener
All ServletContextListeners are notified of context initialization before any filters or servlets in the web application are initialized.
contextInitialized
in interface ServletContextListener
event
- the ServletContextEvent containing the ServletContext
that is being initializedpublic void contextDestroyed(ServletContextEvent event)
javax.servlet.ServletContextListener
All servlets and filters will have been destroyed before any ServletContextListeners are notified of context destruction.
contextDestroyed
in interface ServletContextListener
event
- the ServletContextEvent containing the ServletContext
that is being destroyed