配置ContextLoaderListener报NoClassDefFoundError

202 阅读1分钟

问题:

在web.xml中配置ContextLoaderListener报下面的问题

<!--配置web监听器-->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--配置全局参数-->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

image.png

分析

最开始检查是否是配置文件写错,检查后无误

再检查参数名contextConfigLocation是否写错,检查后无误

再检查是否导入spring集成web的坐标,检查后无误

实在没招了,经网上一篇文章提示,可能是spring监听器缺失,是jar包没有同步发布到项目中进行运行,导致项目运行找不到spring的jar包

解决

maven:clean -> maven:install (实在是没想到是这种原因--)

image.png