java - 严重 : Exception org. springframework.web.util.Log4jConfigListener

标签 java spring spring-mvc

尝试在 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 a log4j.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/

相关文章:

java - Jpa 事务 javax.persistence.RollbackException : Transaction marked as rollbackOnly

java - 带 Spring 的 Hazelcast 配置

java - 尝试向我的 Spring Web Flow2 项目添加安全性

java 相当于 printf ("%*.*f")

java - jetty 6 : How to remove a Servlet?

java - 在 master :8088 中找到 hadoop 2.7.2 中每个任务的容器

java - 列出Android设备中的所有pdf文件

java - Neo4j 4.2 graph repo 保存方法现在不明确

java - Spring与DbUnit集成测试BeanCreationException Java

java - Spring MVC 图片上传使用 Mockmvc 和 JSON 集成测试失败