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

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

相关推荐
nanxun88618 小时前
记一次诡异的 Docker 容器"串包"故障排查
java
用户15630681035120 小时前
Day01 | Java 基础(Java SE)
java
行者全栈架构师1 天前
Maven dependency:tree 的 8 个高级用法
java·后端
行者全栈架构师1 天前
IDEA 中 Maven 项目的 15 个红色报错快速解决方法
java·后端
令人头秃的代码0_01 天前
mac(m5)平台编译openjdk
java
唐青枫2 天前
Java JDBC 实战指南:从 Connection 到事务和连接池
java
一个做软件开发的牛马2 天前
MyBatis-Plus 从零实战:完整搭建可运行 Demo,BaseMapper 零 SQL、Wrapper 条件构造、分页插件与代码生成器详解
java·后端
用户3721574261352 天前
Java 处理 PDF 图片:提取 PDF 中的图片,并压缩 PDF 图片体积
java
用户3721574261352 天前
Java 打印 Word 文档:从基础打印到高级设置
java
用户3521802454753 天前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程