From a1c7b241528869d717b98a2202690a9d103712af Mon Sep 17 00:00:00 2001 From: Gsealy Jiao Date: Mon, 14 Oct 2019 09:58:21 +0800 Subject: [PATCH] remove support @Order annotation in document. --- .../main/asciidoc/spring-cloud-gateway.adoc | 44 +++++++------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-gateway.adoc b/docs/src/main/asciidoc/spring-cloud-gateway.adoc index 4dd9eedc..fccee2e7 100644 --- a/docs/src/main/asciidoc/spring-cloud-gateway.adoc +++ b/docs/src/main/asciidoc/spring-cloud-gateway.adoc @@ -1205,44 +1205,30 @@ The `GlobalFilter` interface has the same signature as `GatewayFilter`. These ar === Combined Global Filter and GatewayFilter Ordering -When a request comes in (and matches a Route) the Filtering Web Handler will add all instances of `GlobalFilter` and all route specific instances of `GatewayFilter` to a filter chain. This combined filter chain is sorted by the `org.springframework.core.Ordered` interface, which can be set by implementing the `getOrder()` method or by using the `@Order` annotation. +When a request comes in (and matches a Route) the Filtering Web Handler will add all instances of `GlobalFilter` and all route specific instances of `GatewayFilter` to a filter chain. This combined filter chain is sorted by the `org.springframework.core.Ordered` interface, which can be set by implementing the `getOrder()` method. -As Spring Cloud Gateway distinguishes between "pre" and "post" phases for filter logic execution (see: How It Works), the filter with the highest precedence will be the first in the "pre"-phase and the last in the "post"-phase. +As Spring Cloud Gateway distinguishes between "pre" and "post" phases for filter logic execution (see: <>), the filter with the highest precedence will be the first in the "pre"-phase and the last in the "post"-phase. .ExampleConfiguration.java [source,java] ---- @Bean -@Order(-1) -public GlobalFilter a() { - return (exchange, chain) -> { - log.info("first pre filter"); - return chain.filter(exchange).then(Mono.fromRunnable(() -> { - log.info("third post filter"); - })); - }; +public GlobalFilter customFilter() { + return CustomGlobalFilter(); } -@Bean -@Order(0) -public GlobalFilter b() { - return (exchange, chain) -> { - log.info("second pre filter"); - return chain.filter(exchange).then(Mono.fromRunnable(() -> { - log.info("second post filter"); - })); - }; -} +public class CustomGlobalFilter implements GlobalFilter, Ordered { -@Bean -@Order(1) -public GlobalFilter c() { - return (exchange, chain) -> { - log.info("third pre filter"); - return chain.filter(exchange).then(Mono.fromRunnable(() -> { - log.info("first post filter"); - })); - }; + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + log.info("custom global filter"); + return chain.filter(exchange); + } + + @Override + public int getOrder() { + return -1; + } } ----