配置中心
yml
- id: system
uri: lb://system
predicates:
- Path=/system/**
filters:
- StripPrefix=1
这里会消去system这一层的请求
网关代码
java
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@Component
public class RequestFilter implements GlobalFilter, Ordered {
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
System.out.println(request.getURI().getPath());
return chain.filter(exchange);
}
@Override
public int getOrder() {
return 0;
}
}
这里就进行全局的拦截然后答应出请求的路径
结论
可以拿到完整的请求的路径的上面的运行的结果是(假设要请求test服务):
java
/system/test