从Spring Boot 3.1.6升级到3.2.x时遇到Jetty Servlet依赖问题
解决Spring Boot 3.2.x升级后jetty-servlets版本缺失问题
问题原因
Spring Boot 3.2.x对Jetty的依赖管理策略做了调整,org.eclipse.jetty:jetty-servlets不再被默认依赖管理自动分配版本号,导致Maven无法解析该依赖的版本。
解决方案
方案1:直接指定兼容版本
在依赖中明确添加与Spring Boot 3.2.x匹配的Jetty版本(Spring Boot 3.2.x默认适配Jetty 12.x系列):
<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlets</artifactId> <version>12.0.7</version> <!-- 可根据Spring Boot 3.2.x具体子版本微调 --> </dependency>
方案2:通过Spring Boot属性统一管理版本
在POM的<properties>中配置Jetty版本属性,让Spring Boot自动关联适配版本,避免硬编码:
<properties> <jetty.version>12.0.7</jetty.version> </properties> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlets</artifactId> </dependency>
方案3:排查并解决依赖冲突
执行Maven命令查看完整依赖树,检查是否有其他依赖引入了不兼容的Jetty版本或覆盖了版本管理:
mvn dependency:tree
若发现冲突,可通过<exclusions>排除冲突的依赖,示例:
<dependency> <!-- 存在冲突的依赖 --> <groupId>xxx</groupId> <artifactId>xxx</artifactId> <exclusions> <exclusion> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlets</artifactId> </exclusion> </exclusions> </dependency>
内容的提问来源于stack exchange,提问作者footpathdriver
相关产品推荐
相关产品推荐

