You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot问题:修正应用类路径以包含兼容版本的指定转换器类

解决Spring Boot类路径中HttpMessageConverter相关类的版本兼容问题

核心问题根源

你遇到的问题是因为类路径中org.springframework.boot.autoconfigure.http.HttpMessageConverters(来自spring-boot-autoconfigure模块)和org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter(来自spring-web模块)的版本不匹配,或是被第三方依赖引入了冲突版本。

具体解决步骤

  • 统一Spring Boot依赖版本(首选方案)
    利用Spring Boot的依赖管理机制确保所有核心依赖版本一致:

    • Maven项目:在pom.xml中引入spring-boot-starter-parent作为父项目,它会自动管理所有starter及关联依赖的版本:
      <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>2.7.14</version> <!-- 选择稳定兼容版本,如2.x最新稳定版或3.x稳定版 -->
          <relativePath/>
      </parent>
      
    • Gradle项目:通过Spring Boot插件管理版本:
      plugins {
          id 'org.springframework.boot' version '2.7.14'
          id 'io.spring.dependency-management' version '1.0.15.RELEASE'
          id 'java'
      }
      
  • 排查并清理冲突依赖
    用依赖树命令找出导致版本冲突的第三方依赖:

    • Maven执行:mvn dependency:tree -Dverbose
    • Gradle执行:./gradlew dependencies
      找到冲突的spring-web或spring-boot-autoconfigure依赖后,在对应的第三方依赖中排除掉:
    <!-- Maven排除示例 -->
    <dependency>
        <groupId>[冲突依赖的groupId]</groupId>
        <artifactId>[冲突依赖的artifactId]</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 显式声明兼容版本(无parent时使用)
    如果项目无法引入spring-boot-starter-parent,在dependencyManagement中手动声明匹配的版本:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
                <version>2.7.14</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>5.3.29</version> <!-- 注意:Spring Boot 2.7.x对应Spring Framework 5.3.x,3.x对应6.x -->
            </dependency>
        </dependencies>
    </dependencyManagement>
    
  • 清理缓存并重新构建
    执行清理和构建命令确保依赖生效:

    • Maven:mvn clean install
    • Gradle:./gradlew clean build

内容的提问来源于stack exchange,提问作者sravan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 17:45:40