依赖spring-cloud-starter-gateway与spring-cloud-gateway-dependencies的区别


✅ 第一个依赖(spring-cloud-starter-gateway

xml 复制代码
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
  • 作用:Spring Cloud Gateway 的启动器(starter),包含运行网关所需的所有核心依赖,如 Netty、路由、过滤器、断言等。
  • 使用场景:在业务项目中引入,用于启动和运行网关服务。

✅ 第二个依赖(spring-cloud-gateway-dependencies

xml 复制代码
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gateway-dependencies</artifactId>
    <version>xxx</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>
  • 作用:Spring Cloud Gateway 的依赖管理(BOM,Bill of Materials),用于统一管理项目中所有 Spring Cloud Gateway 相关依赖的版本号。
  • 使用场景 :通常用于父项目的 <dependencyManagement> 中,帮助子模块统一版本,不包含具体代码,不能直接运行网关功能。

举个例子说明区别

假设你有一个父工程,多个子模块都要用 Spring Cloud Gateway:

  • 在父工程的 pom.xml 中:
xml 复制代码
<dependencyManagement>
    <dependencies>
        <!-- 统一管理版本 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gateway-dependencies</artifactId>
            <version>3.1.5</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
  • 在子模块中:
xml 复制代码
<dependencies>
    <!-- 真正引入网关功能 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
</dependencies>

这样,子模块不需要写版本号,版本由父工程统一管理。


总结一句话

依赖 作用 使用场景
spring-cloud-starter-gateway 引入网关功能,包含所有运行时依赖 业务项目中直接引入
spring-cloud-gateway-dependencies 统一管理网关相关依赖版本(BOM) 父项目 dependencyManagement 中引入

结论

  • 开发网关 → 用 spring-cloud-starter-gateway
  • 管理版本 → 用 spring-cloud-gateway-dependencies(BOM)

这两个依赖不是替代关系 ,而是互补关系

相关推荐
ps酷教程6 小时前
Jackson 解决没有无参构造函数的反序列化问题
java
NiceCloud喜云6 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
_日拱一卒7 小时前
LeetCode:994腐烂的橘子
java·数据结构·算法·leetcode·深度优先
隔窗听雨眠7 小时前
Nginx网关响应慢排查手记
java·服务器·nginx
智慧物业老杨7 小时前
智慧物业合同周期管理系统:从风险预警到智能交接的全流程数智化落地方案
java·人工智能·python
源码宝8 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展
java·后端·源码·springboot·mes系统·源码二开·mes源码
JAVA社区8 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展
金銀銅鐵8 小时前
[Java] 如何理解 class 文件中方法的 descriptor?
java·后端
云烟成雨TD8 小时前
Spring AI Alibaba 1.x 系列【63】AI Agent 长期记忆
java·人工智能·spring
憧憬成为java架构高手的小白9 小时前
苍穹外卖--day09
java·spring boot·百度