diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index f7b18da4018..d2012a901e4 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -703,6 +703,9 @@ public class ServletContextHandler extends ContextHandler */ public void addServletContainerInitializer(ServletContainerInitializer containerInitializer) { + if (!isStopped()) + throw new IllegalStateException("ServletContainerInitializers should be added before starting"); + addServletContainerInitializer(containerInitializer, Collections.emptySet()); } @@ -714,6 +717,9 @@ public class ServletContextHandler extends ContextHandler */ public void addServletContainerInitializer(ServletContainerInitializer containerInitializer, Set> classes) { + if (!isStopped()) + throw new IllegalStateException("ServletContainerInitializers should be added before starting"); + addManaged(new Initializer(this, containerInitializer, classes)); }