WARN No appenders could be found for logger的解决方法

在spring的web项目中常常会在tomcat启动的时候出现这种提示: 
引用
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). 
log4j:WARN Please initialize the log4j system properly.


网上有好多解决办法都不管用,这个提示应该是读入web应用程序的log4j.properties文件之前就报出来了。是在加载org.springframework.web.context.ContextLoader这个listener的时候没找到log4j的配置文件造成的。 

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

Xml代码  收藏代码
  1. <!-- 以下3项参数与log4j的配置相关 -->  
  2.       
  3.     <context-param>  
  4.         <param-name>log4jConfigLocation</param-name>  
  5.         <param-value>classpath:log4j.properties</param-value>  
  6.     </context-param>  
  7.       
  8.     <context-param>  
  9.         <param-name>log4jRefreshInterval</param-name>  
  10.         <param-value>60000</param-value>  
  11.     </context-param>  
  12.     <listener>  
  13.         <listener-class>  
  14.             org.springframework.web.util.Log4jConfigListener  
  15.         </listener-class>  
  16.     </listener>  
  17. <!-- end -->  
  18.   
  19.     <listener>  
  20.         <listener-class>  
  21.             org.springframework.web.context.ContextLoaderListener  
  22.         </listener-class>  
  23.     </listener>  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章