引入依赖
XML
<!-- gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
路由配置
java
server:
port: 8088
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- id: order_route # 路由唯一标识
uri: http://localhost:8020 # 需要转发的地址
# 断言规则 用于路由规则的匹配
predicates:
- Path=/order-serv/**
# http://localhost:8088/order-serv/order/add => http://localhost:8020/order-serv/order/add
filters:
- StripPrefix=1 # 转发去掉第一层路径
# http://localhost:8020/order-serv/order/add => http://localhost:8020/order/add