Spring JpetStore ---- log4j的配置

本文详细介绍了如何解决SpringJpetStore项目中log4j无法记录日志的问题,包括正确设置webAppRootKey、添加Log4jConfigListener监听器及调整log4j.properties文件位置等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
这配置相关
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值