嚴重: 配置類 org.springframework.web.context.ContextLoaderListener 初始化失敗
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
典型原因:web.xml 宣告了 ContextLoaderListener,但專案缺少 spring-web 模組依賴,或 Maven 依賴解析異常導致 JAR 未納入 WEB-INF/lib。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.30</version> <!-- 或統一由 Spring BOM 管理版本 -->
</dependency>
關鍵點:ContextLoaderListener 位於 spring-web 模組,而非 spring-context。
Maven Dependencies 已映射至 WEB-INF/lib~/.m2/repository/org/springframework/spring-web/ 重新下載| Spring 版本 | spring-web 坐標 | 最低 JDK |
|---|---|---|
| 5.3.x | org.springframework:spring-web:5.3.30 | JDK 8+ |
| 6.0.x | org.springframework:spring-web:6.0.13 | JDK 17+ |
| Spring Boot 2.7 | 透過 spring-boot-starter-web 遞移 | JDK 8+ |
| Spring Boot 3.x | 透過 spring-boot-starter-web 遞移 | JDK 17+ |