log4j工作正常,但是,在服务器启动时,我收到这些警告:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
这意味着无法找到log4j.properties.但我不知道如何解决这个问题,因为一切似乎都很好.
将spring Log4jConfigListener作为web.xml中的第一个侦听器.
<listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
您可以在上下文参数中设置upp log4j属性的位置,但如果它放在类路径上则不需要这样做.
一个例子是……
<context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/resources/log4j.properties</param-value> </context-param>
翻译自:https://stackoverflow.com/questions/9691456/log4j-spring-mvc-no-appenders-could-be-found-for-logger