Eclipse常见问题解决 - java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener
现象:
Web项目使用Maven管理jar包依赖,web.xml文件中有如下配置:
- <!-- 配置Spring里的log4j监听器 -->
- <listener>
- <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
- </listener>
原因:
在部署过程中没有将依赖的jar包自动拷贝到/WEB-INF/lib目录下。
解决办法:
选中项目右键,Properties -> Deployment Assembly -> Add... -> Java Build Path Entries -> Maven Dependencies。
这个设置保存在项目的.classpath文件中,也可以直接修改此文件。配置好以后会多出如下一段xml:
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
- </attributes>
- </classpathentry>
参考资料:Maven把依赖包拷贝到lib下