From 9cae416755d69472ce27388d403ae6f71a6d5033 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 25 Jan 2018 11:47:36 +0000 Subject: [PATCH] Explicitly configure and document WebFilter orderings Closes gh-11756 --- .../web/reactive/server/MetricsWebFilter.java | 5 +++- .../main/asciidoc/spring-boot-features.adoc | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilter.java index b4f2d6a84b..a158f4205b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/reactive/server/MetricsWebFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,8 @@ import io.micrometer.core.instrument.Tag; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; @@ -34,6 +36,7 @@ import org.springframework.web.server.WebFilterChain; * @author Jon Schneider * @since 2.0.0 */ +@Order(Ordered.HIGHEST_PRECEDENCE + 1) public class MetricsWebFilter implements WebFilter { private final MeterRegistry registry; diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 0ee1fa1a48..1fb1b90f45 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2641,6 +2641,29 @@ follows: +[[boot-features-webflux-web-filters]] +==== Web Filters +Spring WebFlux provides a `WebFilter` interface that can be implemented to filter HTTP +request-response exchanges. `WebFilter` beans found in the application context will +be automatically used to filter each exchange. + +Where the order of the filters is important they can implemented `Ordered` or be annotated +with `@Order`. Spring Boot auto-configuration may configure web filters for you. When it +does so, the orders shown in the following table will be used: + +|=== +| Web Filter | Order + +|`MetricsWebFilter` +|`Ordered.HIGHEST_PRECEDENCE + 1` + +|`WebFilterChainProxy` (Spring Security) +|`-100` + +|=== + + + [[boot-features-jersey]] === JAX-RS and Jersey If you prefer the JAX-RS programming model for REST endpoints, you can use one of the