public class JohnsonContextListener extends Object implements javax.servlet.ServletContextListener
Johnson with the servlet container.
In web environments, this is the preferred mechanism for managing Johnson's lifecycle, allowing it to be initialised and terminated in a thread-safe context. This listener should be registered before any others except, if applicable, those that setup logging.
To use this listener, add the following to web.xml:
<listener>
<listener-class>com.atlassian.johnson.context.JohnsonContextListener</listener-class>
</listener>
Alternatively, if the application is deployed in a Servlet 3 container such as Tomcat 7, this listener can be
registered in a ServletContainerInitializer using ServletContext.addListener.| Modifier and Type | Field and Description |
|---|---|
static String |
ATTR_REGISTERED
When a
JohnsonContextListener is registered with a
ServletContext, this attribute will be used to mark its registration so that multiple
listeners will not be registered. |
| Constructor and Description |
|---|
JohnsonContextListener() |
| Modifier and Type | Method and Description |
|---|---|
void |
contextDestroyed(javax.servlet.ServletContextEvent event)
Terminates
Johnson. |
void |
contextInitialized(javax.servlet.ServletContextEvent event)
Initialises
Johnson. |
static void |
register(javax.servlet.ServletContext context)
Registers a
JohnsonContextListener with the provided ServletContext if such a listener has not
already been registered. |
public static final String ATTR_REGISTERED
JohnsonContextListener is registered with a
ServletContext, this attribute will be used to mark its registration so that multiple
listeners will not be registered.public static void register(@Nonnull javax.servlet.ServletContext context)
JohnsonContextListener with the provided ServletContext if such a listener has not
already been registered.
This method is for use as part of Servlet 3-style ServletContainerInitializer initialization. Listeners
cannot be added to ServletContext instances after they have already been initialized.
context - the ServletContext to register a JohnsonContextListener withIllegalArgumentException - if the provided ServletContext was not passed to
ServletContainerInitializer.onStartup(java.util.Set, ServletContext)IllegalStateException - if the ServletContext has already been initializedUnsupportedOperationException - if this ServletContext was passed to the
ServletContextListener.contextInitialized(ServletContextEvent) method of a
ServletContextListener that was not either declared in web.xml or
web-fragment.xml or annotated with @WebListenerpublic void contextDestroyed(@Nonnull javax.servlet.ServletContextEvent event)
Johnson.contextDestroyed in interface javax.servlet.ServletContextListenerevent - the context eventJohnson.terminate(javax.servlet.ServletContext)public void contextInitialized(@Nonnull javax.servlet.ServletContextEvent event)
Johnson.contextInitialized in interface javax.servlet.ServletContextListenerevent - the context eventJohnson.initialize(javax.servlet.ServletContext)Copyright © 2017 Atlassian. All rights reserved.