集成 Spring Cloud Gateway

hai-gateway 服务端
引入依赖

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

添加配置

spring:
  application:
    name: cloud-gateway
  cloud:
    gateway:
      routes:
        - id: haiproduct  # 路由的ID,没有固定规则,但要求唯一,建议配合服务名
          # uri: http://localhost:8200  # 单个匹配
          uri: lb://HAI-PRODUCT # 负载均衡,可以访问 8200/8201
          predicates:
            - Path=/product/**  # 断言,根据路径路由  http://localhost:7000/product
        - id: haiapp  # 路由的ID,没有固定规则,但要求唯一,建议配合服务名
          uri: lb://HAI-APP # 负载均衡,可以访问 8080/8081
          predicates:
            - Path=/**  # 断言,根据路径路由    http://localhost:7000

启动类加上注解

@EnableEurekaClient
@SpringBootApplication

**hai-app 客户端注册到 Eureka **
可以通过 gateway 访问 hai-app:
http://localhost:7000

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值