严重:异常org.springframework.web.util.Log4jConfigListener


问题内容

在Spring Tool Suite中尝试运行tomcat时遇到以下严重异常:

SEVERE: Exception sending context initialized event to listener instance of class    org.springframework.web.util.Log4jConfigListener
java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded
at    org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(WebUtils.java:143)
at    org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebConfigurer.java:117)
at    org.springframework.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

问题答案:

不要Log4jConfigListener在没有 扩展 的WAR中使用; 我们可能需要更清楚地说明这一点。

只有两个好处Log4jWebConfigurer:-在Log4J配置文件更改时刷新Log4J配置;-允许使用相对于Web应用程序根目录的日志文件路径。

当未扩展WAR时,两者都不适用,因此Log4jWebConfigurer在这种情况下使用毫无意义。只需依靠log4j.properties类路径根目录中文件中Log4J的默认初始化即可。

顺便说一句,您可能已经注意到Log4jConfigListenerPetclinic和Countrys中已将其注释掉web.xml,原因是相关的:能够部署未扩展的WAR,并且可以在JBoss中轻松地工作(它具有Log4J的特殊用法)

于尔根