谓词 Path · SpringCloud微服务实战 · 看云
8.谓词 Path
导航
Path的使用户方式: 输入两个参数:Spring
PathMatcher表达式列表、【可选】matchOptionalTrailingSeparator标识
本节代码地址
8.1 应用配置
这条路线,如果请求路径是/user/*或、blue/**是可以转发的,例如匹配/user/1或/blue/green
server:
port: 8699
spring:
application:
name: fw-gateways-gateway
profiles:
active: host_route
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
---
spring:
cloud:
gateway:
routes:
- id: host_path_route
uri: lb://fw-cloud-ribbon-server
predicates:
- Path=/user/{segment},/blue/{segment}
profiles: host_path_route
8.2 应用启动
Postman 测试localhost:8699/user/2
将请求地址调整为
@RestController
@RequestMapping("test")
@Slf4j
public class RibbonController {

