tomcat启动时卡死,报:WARN No appenders could be found for logger的解决方法

xiaoxiao2021-02-28  38

在spring的web项目中经常会在tomcat启动的时候出现这种提示: 

[html]  view plain  copy log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).   log4j:WARN Please initialize the log4j system properly.   tomcat被卡死,网上找了些说法,大多数讲没配置log4j,其实配置正确也会出现这个问题;

这个是在加载org.springframework.web.context.ContextLoader这个listener的时候没找到log4j的配置文件造成的。 

1. 确保log4j的配置文件log4j.properties或log4j.xml已经存在(在classpath路径或其他路径下都行,文件内容可参考后面的内容)

2. 没有在web.xml中配置log4j的监听器,如果没有按以下方式配置:

仔细查看web.xml发现在加载org.springframework.web.context.ContextLoader这个listener之后才加载org.springframework.web.util.Log4jConfigListener,把log4j的配置放到org.springframework.web.context.ContextLoader之前,就可以解决这个问题了。

[html]  view plain  copy <!-- 以下3项参数与log4j的配置相关 -->                <context-param>            <param-name>log4jConfigLocation</param-name>            <param-value>/WEB-INF/log4j.properties</param-value>        </context-param>                <context-param>            <param-name>log4jRefreshInterval</param-name>            <param-value>60000</param-value>        </context-param>        <listener>            <listener-class>                org.springframework.web.util.Log4jConfigListener            </listener-class>        </listener>    <!-- end -->            <listener>            <listener-class>                org.springframework.web.context.ContextLoaderListener            </listener-class>        </listener>     转自:http://lveyo.iteye.com/blog/418376

仔细查看web.xml发现在加载org.springframework.web.context.ContextLoader这个listener之后才加载org.springframework.web.util.Log4jConfigListener,把log4j的配置放到org.springframework.web.context.ContextLoader之前,就可以解决这个问题了。
转载请注明原文地址: https://www.6miu.com/read-2622196.html

最新回复(0)