From 1c6f2af475abd4321c9a455f0b2192dab5fffcb8 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 5 Nov 2019 10:02:08 +0000 Subject: [PATCH] Clarify how to configure a Filter's order Closes gh-18266 --- .../src/main/asciidoc/spring-boot-features.adoc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 8214d6057c..d9b7115373 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 @@ -2676,7 +2676,10 @@ Here are a few examples of Filters and their respective order (lower order value It is usually safe to leave Filter beans unordered. -If a specific order is required, you should avoid configuring a Filter that reads the request body at `Ordered.HIGHEST_PRECEDENCE`, since it might go against the character encoding configuration of your application. +If a specific order is required, you should annotate the `Filter` with `@Order` or make it implement `Ordered`. +You cannot configure the order of a `Filter` by annotating its bean method with `@Order`. +If you cannot change the `Filter` class to add `@Order` or implement `Ordered`, you must define a `FilterRegistrationBean` for the `Filter` and set the registration bean's order using the `setOrder(int)` method. +Avoid configuring a Filter that reads the request body at `Ordered.HIGHEST_PRECEDENCE`, since it might go against the character encoding configuration of your application. If a Servlet filter wraps the request, it should be configured with an order that is less than or equal to `OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER`. WARNING: Take care when registering `Filter` beans since they are initialized very early in the application lifectyle.