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

Spring Boot响应式应用默认启动Tomcat而非Netty问题排查

Why Your Spring Boot Reactive App is Using Tomcat Instead of Netty

Hey there! Let's break down why your WebFlux app is spinning up Tomcat instead of the expected Netty server, and how to fix it.

The Root Cause

The issue traces back to your spring-boot-starter-data-rest dependency. Under the hood, this starter automatically pulls in spring-boot-starter-web — the core dependency for Spring MVC, the traditional Servlet-based stack.

Spring Boot's auto-configuration logic has a key priority rule here: if both Spring MVC and Spring WebFlux dependencies are present on the classpath, it defaults to enabling the Servlet stack (Tomcat). Even with @EnableWebFlux added to your main class, this gets overridden because Spring Boot assumes you want to use the Servlet environment when both stacks are available.

How to Fix It

You need to exclude the unwanted spring-boot-starter-web dependency from spring-boot-starter-data-rest so only the WebFlux stack remains. Here's how to update your pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
    <exclusions>
        <!-- Exclude Spring MVC dependency to force WebFlux + Netty -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Bonus Tip

You can actually remove the @EnableWebFlux annotation from your main class. When no Spring MVC dependency is present, Spring Boot's auto-configuration will automatically set up the WebFlux environment with Netty. Adding @EnableWebFlux disables some of these default auto-configurations, which you likely don't need unless you're customizing WebFlux settings explicitly.

After making these changes, restart your app. You should see log output confirming Netty has started on port 8080 instead of Tomcat.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 06:22:24