Spring JpetStore ---- log4j的配置

来源:互联网 发布:数控机床螺纹编程 编辑:程序博客网 时间:2024/05/22 10:37
 

Spring JpetStore ---- log4j的配置

问题的提出:
log4j不能输入信息.
问题的解决: 
1、首先弄清 webAppRootKey 所表示的含义。
<!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"-->
定义完成后就可以在properties文件中用"${} "的方式加以引用了。
如:在 jpetstore的文件中我这样定义:
<display-name>Spring JPetStore</display-name>
<description>Spring JPetStore sample application</description>
<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>petstore.root</param-value>
</context-param>
在log4j.properties文件中:
log4j.appender.logfile.File=${petstore.root}/WEB-INF/petstore.log
可以这样引用。
2、在web.xml文件中加入监听。
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
3、log4j.properties文件在webinf下,而不是在web-inf/classes下。并不是说非得放在这里。这与
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
这配置相关