齐局过滤器感化于全部的道由,没有须要零丁设置,尔们能够用它去告竣许多一致化处置的营业需要,例如权利认证,IP拜候限定等等。
民圆文档:
https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#gatewayfilter-factories
鉴于民圆尔们编写齐局过滤器代码
packagecn.itcast.gateway;importorg.springframework.cloud.gateway.filter.GatewayFilterChain;importorg.springframework.cloud.gateway.filter.GlobalFilter;importorg.springframework.core.Ordered;importorg.springframework.core.annotation.Order;importorg.springframework.stereotype.Component;importorg.springframework.util.MultiValueMap;importorg.springframework.web.server.ServerWebExchange;importreactor.core.publisher.Mono;//@Order(-1)@ComponentpublicclassCustomGlobalFilterimplementsGlobalFilter,Ordered{@OverridepublicMono<Void>filter(ServerWebExchangeexchange,GatewayFilterChainchain){System.out.println("----->>>>>>customglobalfilter");MultiValueMap<String,String>paras=exchange.getRequest().getQueryParams();if("javacui".equals(paras.getFirst("username"))){System.out.println("----->>>>>>welcomeadmincome");}returnchain.filter(exchange);}@OverridepublicintgetOrder(){return-1;}}即使生活多个过滤器,那末Order用于指定施行程序。
推举您浏览更多相关于“ springCloudGateway齐局过滤器 ”的作品