Log4j,Spring MVC,没有可用于记录器的appender

l a*_*a s 7 log4j spring-mvc

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.
Run Code Online (Sandbox Code Playgroud)

这意味着log4j.properties无法找到.但我不知道如何解决这个问题,因为一切似乎都很好.

Mar*_*all 17

将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> 
Run Code Online (Sandbox Code Playgroud)

您可以在上下文参数中设置upp log4j属性的位置,但如果它放在类路径上则不需要这样做.

一个例子是......

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/resources/log4j.properties</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)


Joh*_*hnP 6

将这两行代码移到web.xml的顶部以解决问题.

<!-- location of log4j config file -->
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>

<!-- applies log4j configuration -->
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)