依赖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)

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

相关推荐
雨中飘荡的记忆6 小时前
ElasticJob分布式调度从入门到实战
java·后端
考虑考虑14 小时前
JDK25模块导入声明
java·后端·java ee
_小马快跑_15 小时前
Java 的 8 大基本数据类型:为何是不可或缺的设计?
java
Re_zero18 小时前
线上日志被清空?这段仅10行的 IO 代码里竟然藏着3个毒瘤
java·后端
洋洋技术笔记18 小时前
Spring Boot条件注解详解
java·spring boot
程序员清风2 天前
程序员兼职必看:靠谱软件外包平台挑选指南与避坑清单!
java·后端·面试
皮皮林5512 天前
利用闲置 Mac 从零部署 OpenClaw 教程 !
java
华仔啊2 天前
挖到了 1 个 Java 小特性:var,用完就回不去了
java·后端
SimonKing2 天前
SpringBoot整合秘笈:让Mybatis用上Calcite,实现统一SQL查询
java·后端·程序员
日月云棠2 天前
各版本JDK对比:JDK 25 特性详解
java