diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index d7290cf4170..3672db4c0f2 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -51,18 +51,32 @@ public class AnnotationConfiguration extends AbstractConfiguration private static final Logger LOG = Log.getLogger(AnnotationConfiguration.class); public static final String CLASS_INHERITANCE_MAP = "org.eclipse.jetty.classInheritanceMap"; public static final String CONTAINER_INITIALIZERS = "org.eclipse.jetty.containerInitializers"; - - + public static final String CONTAINER_INITIALIZER_LISTENER = "org.eclipse.jetty.containerInitializerListener"; + + protected List _discoverableAnnotationHandlers = new ArrayList(); protected ClassInheritanceHandler _classInheritanceHandler; protected List _containerInitializerAnnotationHandlers = new ArrayList(); + - + @Override public void preConfigure(final WebAppContext context) throws Exception { } - + + @Override + public void deconfigure(WebAppContext context) throws Exception + { + context.removeAttribute(CLASS_INHERITANCE_MAP); + context.removeAttribute(CONTAINER_INITIALIZERS); + ServletContainerInitializerListener listener = (ServletContainerInitializerListener)context.getAttribute(CONTAINER_INITIALIZER_LISTENER); + if (listener != null) + { + context.removeBean(listener); + context.removeAttribute(CONTAINER_INITIALIZER_LISTENER); + } + } /** * @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext) @@ -224,8 +238,12 @@ public class AnnotationConfiguration extends AbstractConfiguration //add a bean which will call the servletcontainerinitializers when appropriate - ServletContainerInitializerListener listener = new ServletContainerInitializerListener(); + ServletContainerInitializerListener listener = (ServletContainerInitializerListener)context.getAttribute(CONTAINER_INITIALIZER_LISTENER); + if (listener != null) + throw new IllegalStateException("ServletContainerInitializerListener already exists"); + listener = new ServletContainerInitializerListener(); listener.setWebAppContext(context); + context.setAttribute(CONTAINER_INITIALIZER_LISTENER, listener); context.addBean(listener, true); }