修改pom.xml中Spring Boot版本为2.x后类路径兼容错误的解决求助
Spring Boot 3.x降级到2.7.x后类路径兼容问题解决方案
问题根源
你遇到的类兼容错误,核心原因是spring-hateoas版本与Spring Boot 2.7.6不匹配:
- 你手动指定了
spring-hateoas的版本为2.0.0,这个版本是为Spring Boot 3.x设计的,其中org.springframework.plugin.core.config.PluginRegistriesBeanDefinitionRegistrar类的实现和Spring Boot 2.x依赖的Spring框架版本(5.3.x)不兼容。
修复步骤
1. 修正spring-hateoas依赖版本
Spring Boot的parent pom已经为所有starter和关联依赖管理了兼容版本,你不需要手动指定spring-hateoas的版本,直接移除<version>2.0.0</version>即可,让parent自动匹配2.7.6对应的兼容版本(1.9.x系列):
<dependency> <groupId>org.springframework.hateoas</groupId> <artifactId>spring-hateoas</artifactId> <!-- 移除手动指定的version,使用parent管理的兼容版本 --> </dependency>
2. 修正lombok排除配置的拼写错误
你的spring-boot-maven-plugin配置中,lombok的groupId拼写错误(多了一个横杠),修正为正确的org.projectlombok:
<exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude>
完整修正后的核心片段参考
<!-- 依赖部分 --> <dependencies> <!-- 其他原有依赖保持不变 --> <dependency> <groupId>org.springframework.hateoas</groupId> <artifactId>spring-hateoas</artifactId> </dependency> <!-- 其他原有依赖保持不变 --> </dependencies> <!-- build插件部分 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${project.parent.version}</version> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build>
修复完成后,执行mvn clean install刷新依赖,类路径兼容问题即可解决。
内容的提问来源于stack exchange,提问作者lochlannoneill
相关产品推荐
相关产品推荐

