【Java.Spring.MVC】Spring MVC中的监听器 Listener


org.springframework.web.util.Log4jConfigListener

Spring通过org.springframework.web.util.WebAppRootListener 这个监听器来运行时的项目路径。

但是如果在web.xml中已经配置了 org.springframework.web.util.Log4jConfigListener这个监听器,

则不需要配置WebAppRootListener了。因为Log4jConfigListener已经包含了WebAppRootListener的功能.


通过配置参数:

<context-param>  
        <param-name>log4jConfigLocation</param-name>  
        <param-value>/config/log4j.properties</param-value>  
</context-param>

该监听器会加载对应参数,并使用这个路径加载 log4j 的配置文件。

同时在 log4j 的配置文件中,可以使用web.xml中的参数WebAppRootKey ,指定log文件的输出目录(在当前web项目下):

<context-param>  
        <param-name>webAppRootKey</param-name>  
        <param-value>gof.webapp.root</param-value>  
</context-param> 

log4j.appender.gofFile = org.apache.log4j.RollingFileAppender  
log4j.appender.gofFile.File =${gof.webapp.root}/logs/gof.log 
log4j.appender.gofFile.MaxFileSize = 500MB  
log4j.appender.gofFile.MaxBackupIndex = 1000  
log4j.appender.gofFile.layout = org.apache.log4j.PatternLayout  
log4j.appender.gofFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t]-[%p]-[%l] - %m%n 

参见: http://blog.csdn.net/liuyanghai/article/details/7802405

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值