尝试在 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)
最佳答案
Don't use
Log4jConfigListener
within a WAR that is not expanded; we probably need to make that even clearer.There's only two benefits that
Log4jWebConfigurer
gives you: - refreshes Log4J configuration when the Log4J config file changes; - allows to use log file paths relative to the web applicaiton root.Both are not applicable when the WAR is not expanded, so there's no point in using
Log4jWebConfigurer
in such a scenario. Simply rely on Log4J's default initialization from alog4j.properties
file in the root of the classpath.BTW, you might have noticed that
Log4jConfigListener
is commented-out in Petclinic's and Countries'web.xml
, for a related reason: To be able to deploy WARs that are not expanded, and to work without hassle in JBoss (which has its own special usage of Log4J).Juergen
关于java - 严重 : Exception org. springframework.web.util.Log4jConfigListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24336386/