ClassNotFoundException :org.springframework.web.util.Log4jConfigServlet

,

1、问题:

在Spring v4.1.7环境中配置log4j参数时,使用Servlet方式加载log4j.properties文件,发现出现下面的异常:

ClassNotFoundException :org.springframework.web.util.Log4jConfigServlet

在web.xml中使用下面的配置方式,将会报上述异常。

<context-param>   
	<param-name>log4jConfigLocation</param-name>   
	<param-value>WEB-INF/classes/log4j.properties</param-value>  
</context-param>  


<servlet> 
	<servlet-name>log4jConfigListener</servlet-name>
	<servlet-class>org.springframework.web.util.Log4jConfigServlet</servlet-class>
	<load-on-startup>0</load-on-startup>
</servlet>

 

2、原因:

Spring v4.1.7版本的web包中已去掉了名为为Log4jConfigServlet的类,而在Spring v2.5.4中是存在该类的,但监听器类Log4jConfigListener还存在。

3、解决:

使用监听器方式实现。Spring v4.1.7 web包:spring-web-4.1.7.RELEASE.jar。

	<context-param>   
		<param-name>log4jConfigLocation</param-name>   
		<param-value>WEB-INF/classes/log4j.properties</param-value>  
	</context-param>  
	<listener>   
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
	</listener>   

参考:

1. log4j 几个技巧. http://blog.csdn.net/hongweigg/article/details/7085895.

posted @ 2015-12-03 21:37  hongweigg  阅读(52)  评论(0)    收藏  举报