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

Spring Boot启动报错:HttpMessageConvertersAutoConfiguration条件处理失败

问题:Spring Boot启动报错HttpMessageConvertersAutoConfiguration相关错误

启动Spring Boot应用时出现以下错误:

Error processing condition on org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration.stringHttpMessageConverter

项目的pom.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>my-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>roomboss-assignment</name>
    <description>my-app</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

项目通过Spring Initializer创建,使用Maven构建,已执行mvn clean install,仅编写了模型、仓库和控制器,计划实现CRUD,但无法启动。


错误成因与解决方案

成因分析

你同时引入了spring-boot-starter-web和spring-boot-starter-webflux依赖,这两个starter会触发Spring Boot自动配置的冲突:

  • spring-boot-starter-web基于Servlet栈,依赖Spring MVC,默认使用Tomcat作为嵌入式容器;
  • spring-boot-starter-webflux基于Reactive栈,依赖Spring WebFlux,默认使用Netty作为嵌入式容器。

当两者共存时,Spring Boot的自动配置在处理HttpMessageConverters(消息转换器)时会出现条件判断冲突,导致StringHttpMessageConverter的配置逻辑执行失败,进而抛出启动错误。

解决方案

根据你的CRUD需求(常规同步接口),只需要保留spring-boot-starter-web依赖,移除spring-boot-starter-webflux即可:

修改pom.xml,删除以下依赖块:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

之后重新执行mvn clean install,再启动应用即可解决该错误。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 23:08:20