服务网关Gateway_入门案例

创建cloud-gateway-gateway9527工程

pom文件引入依赖

复制代码
<dependencies>
    <!--  引入网关Gateway依赖   -->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.22</version>
    </dependency>
  </dependencies>

新增application.yml

复制代码
server:
  port: 9527

spring:
  cloud:
    gateway:
      routes:
        # 路由ID,没有固定规则但要求唯一,建议配合服务名
        - id: cloud-order-openfeign-consumer
        # 匹配后提供服务的路由地址
          uri: http://localhost:80
        # 断言3
        # http://localhost:9527/order/index
          predicates:
            # 路径相匹配的进行路由
            - Path=/order/*

主启动类

java 复制代码
@Slf4j
@EnableEurekaClient
@SpringBootApplication
public class GatewayMain {
  public static void main(String[] args) {
    SpringApplication.run(GatewayMain.class,args);
    log.info("********** GatewayMain 服务启动成功 *********");
   }
}

测试

  • 启动注册中心 7001,7002
  • 启动服务提供者80
  • 启动网关服务9527

请求localhost:9527/order/index

相关推荐
其实防守也摸鱼5 小时前
CTF密码学综合教学指南--第五章
开发语言·网络·笔记·python·安全·网络安全·密码学
S1998_1997111609•X6 小时前
论mysql国盾shell-sfa犯罪行为集团下的分项工程及反向注入原理尐深度纳米算法下的鐌檵鄐鉎行为
网络·数据库·网络协议·百度·开闭原则
AI精钢7 小时前
AI Agent 从上线到删库跑路始末
网络·人工智能·云原生·aigc
笨笨饿8 小时前
69_如何给自己手搓一个串口
linux·c语言·网络·单片机·嵌入式硬件·算法·个人开发
geneculture9 小时前
《智能通信速分多次传输技术(VDMT)》专利文件的全文汉英双语对照版本
服务器·网络·人工智能·融智学的重要应用·哲学与科学统一性·融智时代(杂志)·人机间性
xrui5810 小时前
2026实战:深度解析 Gemini 3.1 镜像站函数调用在自动化运维工单中的应用
linux·服务器·网络
Python私教10 小时前
GenericAgent记忆系统深度解析:四层架构如何让AI拥有永不遗忘的大脑
网络·人工智能·架构
时空系11 小时前
第9篇:成员功能——为结构体添加能力 Rust中文编程
开发语言·网络·rust
@encryption11 小时前
VLAN --- 深度学习
网络
@insist12312 小时前
信息安全工程师-虚拟专用网络核心技术与软考考点全解析
网络·软考·信息安全工程师·软件水平考试