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

相关推荐
Cx330❀10 小时前
【Linux网络】网络层协议 IP :从网络层原理到 Linux 内核源码
linux·运维·服务器·网络·tcp/ip·ai·ai编程
FPC工厂——皇榜科技12 小时前
机器人灵巧手线路板:从“握得住”到“摸得准”:一只机械手的柔性神经密码
网络·人工智能·科技·机器人·pcb工艺
Orange_sparkle12 小时前
Pi Agent vs LangGraph:从人机交互、企业 RAG 到持久化工作流的完整选型指南
java·网络·人机交互
xiaoye-duck13 小时前
《Linux 网络编程》深入传输层 UDP 协议原理:端口、报文、缓冲区与内核源码解析
linux·网络·udp
好评12414 小时前
【Linux】数据链路层
linux·运维·网络
天衍四九-14 小时前
第一章:从 LLM 到 Agent —— DeepSeek Harness 入门
网络·数据库·人工智能·python
Jae den14 小时前
网络丢包是什么?
网络
Raas10015 小时前
AI网关和LiteLLM区别在哪?MAI Gateway(魔芋企业级AI网关)统一治理方案深度解析
大数据·人工智能·gateway·mai gateway·企业级产品
XR12345678815 小时前
医院无线整网高密覆盖选型深度解析
运维·网络
发量惊人的中年网工15 小时前
企业一体化安全网关选型:适用规模、需求架构与实施建议
网络