当前位置: 首页 > news >正文

Spring Cloud Gateway网关路由配置 - AlanLee

Spring Cloud Gateway 配置使用 lb:// 协议时,需依赖以下组件:

核心依赖

‌Spring Cloud Gateway 依赖‌
需添加 spring-cloud-starter-gateway 依赖,用于启用网关功能。 ‌
 
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

服务注册中心依赖‌

若使用 lb:// 格式(即服务发现模式),需引入服务注册中心组件,例如Nacos 或 Eureka 的 Spring Cloud 启动器:
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

负载均衡器依赖‌

需引入 spring-cloud-starter-loadbalancer 依赖,用于实现服务发现和负载均衡:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>

配置要求

‌服务发现配置‌:确保 Nacos/Eureka 等服务注册中心已正确配置,且服务已注册。 ‌
‌路由配置示例‌:
# Tomcat
server:port: 8080# Spring
spring:application:# 应用名称name: test-gatewayprofiles:# 环境配置active: devcloud:nacos:discovery:# 服务注册地址server-addr: 127.0.0.1:8848gateway:routes:# 系统模块- id: test-systemuri: lb://test-systempredicates:- Path=/system/**filters:- StripPrefix=1
 
技术博主:AlanLee
博客地址:http://www.cnblogs.com/AlanLee
GitHub地址:https://github.com/AlanLee-Java
http://www.zskr.cn/news/30862.html

相关文章:

  • 重构学习认知:从听讲、践行到教学的启示
  • 域登录态分享(类sso)
  • MPK(Mirage Persistent Kernel)源码笔记(2)--- 多层结构化图模型
  • day000 ML串讲
  • cmd运行python文件
  • 事倍功半是蠢蛋57 typora相对路径图片上传到github
  • 2025 年 10 月门窗十大品牌综合实力权威推荐榜单,聚焦产能、专利与环保的实力品牌深度解析
  • 以“听”为基,以“做”为翼
  • 解码Linux文件IO之中文字库原理与应用
  • 完整教程:突破NER性能瓶颈:BERT与LLM协同的混合架构实践
  • AVCodecContext,AVFormatContext区别
  • 题解:P5853 [USACO19DEC] Tree Depth P
  • idea或pycharm工具报python packaging tools not found. install packaging tools
  • [K230学习笔记 02] I2C - Ze
  • javascript 学习笔记(有c++基础)(更新中)
  • MCP Router使用学习
  • 人生八要(摘抄)
  • 20232322 2025-2026-1 《网络与系统攻防技术》实验三实验报告
  • 2025年上海久宙集团:深度解析技术护城河与行业话语权
  • 2025年欧那德语深度解析:十二年在线小班模式全透视
  • LangChain简单介绍
  • LLM-提示词
  • 图像分类,从网络构建到断点续训,TF2版本实现
  • C0427 【20251025】2025 CSP-J 联测5 总结
  • 2025 年 10 月贵州旅游旅行社最新推荐,精准检测与稳定性能深度解析
  • PyTorch API 详细中文文档,基于PyTorch2.5
  • 20232417 2025-2026-1 《网络与系统攻防技术》实验三实验报告
  • OpenLayers地图交互 -- 章节十八:拖拽旋转和缩放交互详解 - 教程
  • 小白 / 学生党必藏!真正有效的最佳安卓数据恢复软件
  • LeetCode边界与内部和相等的稳定子数组