服务网关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

相关推荐
网络研究院1 小时前
LastPass 发布紧急安全预警:针对主密码的活跃网络钓鱼攻击正在进行中
网络·安全·黑客·攻击·漏洞·风险·钓鱼
向夏威夷 梦断明暄3 小时前
【高效管理token成本】OpenClaw精细化分库管理memory以减少token成本的方案的可行性研究
网络
aixingkong9216 小时前
AI超节点Scale Up域总线各层优化设计
linux·服务器·网络
瓦学妹8 小时前
为什么您的AI总是显示“不支持的区域”?如何解决?
大数据·网络·人工智能
优化Henry9 小时前
5G站点软件错误告警与资源激活超时两类典型告警分析与处理
网络·笔记·学习·5g·信息与通信
coward919 小时前
千兆以太网卡(Ethernet)驱动初始化完成,但是无法udhcpc获取ip
服务器·网络·嵌入式硬件·tcp/ip
逸Y 仙X9 小时前
跨语言RPC框架Thrift实战
网络·网络协议·rpc·thrift
软件技术员10 小时前
SSL.com 证书:免费单域名 90 天证书
网络·网络协议·ssl
腾霄星月10 小时前
内网横向移动全套实操重点知识总结
网络·安全·网络安全
茉莉玫瑰花茶11 小时前
IP 分片和组装的具体过程
服务器·网络·tcp/ip