log4j.properties对于web app摆放的位置
我原来通常都是把 log4j.properties放在WEB-INF目录下, web.xml相应的定义为:
<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>
这个设置对于该web app没有任何问题。但是如果你要进行JUnit Test,在运行TestCase时,就会发生错误:
log4j:WARN No appenders could be found for logger
log4j:WARN Please initialize the log4j system properly.
那是因为在classpath里找不到log4j.properties,因此我把log4j.properties改放在WEB-INF/classes目录下,web.xml相应的定义改为:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
这样运行Junit时也会正常!
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/totogogo/archive/2007/05/01/1593885.aspx