Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
cbc17c23
Commit
cbc17c23
authored
Jul 15, 2019
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it easier to determine each servlet filter's order
Closes gh-17520
parent
8aed0645
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
24 deletions
+10
-24
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+9
-24
AbstractFilterRegistrationBean.java
...work/boot/web/servlet/AbstractFilterRegistrationBean.java
+1
-0
No files found.
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
cbc17c23
...
...
@@ -3229,34 +3229,19 @@ If convention-based mapping is not flexible enough, you can use the
`ServletRegistrationBean`, `FilterRegistrationBean`, and
`ServletListenerRegistrationBean` classes for complete control.
Spring Boot ships with many auto-configurations that may define Filter beans. Here are a
few examples of Filters and their respective order (lower order value means higher
precedence):
|===
| Servlet Filter | Order
|`OrderedCharacterEncodingFilter`
|`Ordered.HIGHEST_PRECEDENCE`
|`WebMvcMetricsFilter`
|`Ordered.HIGHEST_PRECEDENCE + 1`
|`ErrorPageFilter`
|`Ordered.HIGHEST_PRECEDENCE + 1`
|`HttpTraceFilter`
|`Ordered.LOWEST_PRECEDENCE - 10`
|===
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
Filter beans can be ordered to control their position in the filter chain by using
`@Order` or implemented `Ordered`. It is usually safe to leave Filter beans unordered.
However, 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 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`.
TIP: To see the order of every `Filter` in your application, enable debug level logging
for the `web` <<boot-features-custom-log-groups,logging group>>
(`logging.level.web=debug`). Details of the registered filters, including their order and
URL patterns, will then be logged at startup.
[[boot-features-embedded-container-context-initializer]]
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBean.java
View file @
cbc17c23
...
...
@@ -260,6 +260,7 @@ public abstract class AbstractFilterRegistrationBean<T extends Filter> extends D
builder
.
append
(
" urls="
).
append
(
this
.
urlPatterns
);
}
}
builder
.
append
(
" order="
).
append
(
getOrder
());
return
builder
.
toString
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment