错误现象:
每次启动Tomcat6.0总会出现如下提示,但不影响Tomcat正常运行。提示如下:
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.
问题原因:
之前是通过设置Servlet自启动来初始化Log4j的配置,因此可能与后面采用的Spring不兼容。
原配置如下:
<servlet>
<description>启动并初始化Log4j,启动定时扫描任务</description>
<servlet-name>InitServlet</servlet-name>
<servlet-class>servlet.InitServlet</servlet-class>
<init-param>
<param-name>log4jConfigFile</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
解决方法:
使用org.springframework.web.util.Log4jConfigListener配置代替自定义的InitServlet来初始化Log4j,即删除InitServlet配置
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
注意:要严格按照以上配置顺序。
--转自