Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.5
-
None
Description
I tried to integrate jacoco in my maven web project.
However it always failed with the following logs:
[WARNING] FAILED o.e.j.m.p.JettyWebAppContext@1d831c2
{/,file:/D:/works/paypos2/jacoco-spring/src/main/webapp/,UNAVAILABLE} {file:/D:/works/paypos2/jacoco-spring/src/main/webapp/}: java.lang.IllegalStateException: C
ontext destroyed before it was initialized.
java.lang.IllegalStateException: Context destroyed before it was initialized.
at org.apache.logging.log4j.web.Log4jServletContextListener.contextDestroyed(Log4jServletContextListener.java:55)
I read the code and found Exception throw in org.apache.logging.log4j.web.Log4jServletContextListener.contextDestroyed:
if (this.servletContext == null || this.initializer == null)
{ throw new IllegalStateException("Context destroyed before it was initialized."); }This runtime exception fails jetty-maven-plugin web application configuration validation.
So I have to write my own Listener to work around: (Log4jWebLifeCycle is not public, so I have to use public interface to operate.)
public void contextDestroyed(final ServletContextEvent event) {
// if (this.servletContext == null || this.initializer == null)
// LOGGER.debug("Log4jServletContextListener ensuring that Log4j shuts down properly.");
if (this.initializer != null) {
if (this.initializer instanceof Log4jWebSupport)
this.initializer.stop();
}
}
I think using a warning log is better than throw an exception in contextDestroyed, because this is shutting down stage.