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

Spring Boot 2响应式项目启动时未用Netty,默认启动Tomcat问题

Why Your Spring Boot 2 WebFlux App Starts Tomcat Instead of Netty

Hey there! I’ve run into this exact snag before—let’s break down what’s going on and how to fix it.

The Root Cause

Spring Boot’s auto-configuration picks a server based on what’s in your classpath:

  • When you use spring-boot-starter-webflux, Netty is the default reactive server out of the box.
  • But if any Servlet-stack dependencies sneak into your classpath (like spring-boot-starter-web), Spring Boot will automatically switch to a Servlet container (Tomcat, by default) instead of Netty.

Looking at your dependencies, the culprit is almost certainly spring-boot-starter-hateoas. In Spring Boot 2.x, this starter automatically pulls in spring-boot-starter-web (the traditional Servlet stack) unless you explicitly exclude it. That’s why Tomcat is firing up instead of Netty.

Fix Steps

  • Exclude the Servlet stack from the HATEOAS starter
    Modify your spring-boot-starter-hateoas dependency in build.gradle to exclude the unwanted spring-boot-starter-web module:

    compile("org.springframework.boot:spring-boot-starter-hateoas:${springBootVersion}") {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-web'
    }
    
  • Verify your dependency tree
    Run this command to double-check that no Servlet-related dependencies are still lurking in your project:

    ./gradlew dependencies
    

    Look for entries like org.springframework.boot:spring-boot-starter-tomcat—if you still see them, trace back to which starter is bringing them in and repeat the exclusion step.

  • Rebuild and restart
    After making the changes, rebuild your project and start the app. It should now use Netty as the default server for your reactive WebFlux application.

Quick Note

If you’re using any other starters (like spring-boot-starter-data-jdbc or similar), make sure none of them are pulling in spring-boot-starter-web accidentally. The dependency tree check will help you spot those hidden dependencies.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:30:30