Spring Cloud 系列之 Gateway 服务网关(三)
本篇文章为系列文章,未读第一集的同学请猛戳这里: Spring Cloud 系列之 Gateway 服务网关(一) Spring Cloud 系列之 Gateway 服务网关(二) 本篇文章讲解 Gateway 网关过滤器和全局过滤器以及自定义过滤器。 过滤器 Spring Cloud Gateway 根据作用范围划分为 GatewayFilter 和 GlobalFilter ,二者区别如下: GatewayFilter :网关过滤器,需要通过 spring.cloud.routes.filters 配置在具体路由下,只作用在当前路由上或通过 spring.cloud.default-filters 配置在全局,作用在所有路由上。 GlobalFilter :全局过滤器,不需要在配置文件中配置,作用在所有的路由上,最终通过 GatewayFilterAdapter 包装成 GatewayFilterChain 可识别的过滤器,它为请求业务以及路由的 URI 转换为真实业务服务请求地址的核心过滤器,不需要配置系统初始化时加载,并作用在每个路由上。 网关过滤器 GatewayFilter 点击链接观看: 网关过滤器视频 (获取更多请关注公众号「哈喽沃德先生」) 网关过滤器用于拦截并链式处理 Web 请求,可以实现横切与应用无关的需求,比如