Spring Cloud 微服务开发:入门、进阶与源码剖析 —— 9.5 Spring Cloud Gateway 过滤器工厂

9.5 Spring Cloud Gateway 过滤器工厂

过滤器允许以某种方式修改传入的HTTP请求或传出的HTTP响应。过滤器可以限定作用在某些特定请求路径上。 Spring Cloud Gateway包含许多内置的GatewayFilter工厂。

GatewayFilter工厂同上一篇介绍的Predicate工厂类似,都是在配置文件application.yml中配置,遵循了约定大于配置的思想。在配置文件中配置的GatewayFilter Factory最终都会相应的过滤器工厂类处理。

现在挑几个常见的过滤器工厂来讲解。

9.5.1 AddRequestHeader过滤器工厂

AddRequestHeader过滤器工厂支持两个参数,一个是属性名一个为属性值。用于对匹配上的请求加上header。

1.ch9_5_gateway_filter_addrequestheader

(1)引入依赖

父项目的pom文件已引入依赖。

代码清单:ch9_5/pom.xml


<dependency>
    <groupId>org.springframework.cloud

猜你喜欢

转载自blog.csdn.net/meteor_93/article/details/104482848