主要是增加一个 route,其他配置不变
routes:- id: service_customeruri: lb://CONSUMERorder: 0predicates:- Path=/customer/**filters:- StripPrefix=1- AddResponseHeader=X-Response-Default-Foo, Default-Bar
新增的StripPrefix可以接受一个非负整数,对应的具体实现是StripPrefixGatewayFilterFactory,从名字就可以看出它的作用是去掉前缀的,那个整数即对应层数。具体到本例中,我们通过 Spring Cloud Gateway 访问 /customer/hello/windmt,那么当网关服务向后转发请求时,会去掉/customer,微服务收到的就是/hello/windmt。