You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document custom servlet filters in Web MVC section
Add information to the Filters section about creating custom
filters by implementing `javax.servlet.Filter` or extending
Spring's `GenericFilterBean` and `OncePerRequestFilter`.
This brings consistency with the WebFlux documentation, which
already explains custom filters via `WebFilter`.
Signed-off-by: 99hyeon <[email protected]>
Copy file name to clipboardExpand all lines: framework-docs/modules/ROOT/pages/web/webmvc/filters.adoc
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,35 @@ Servlet filters can be configured in the `web.xml` configuration file or using S
15
15
If you are using Spring Boot, you can
16
16
{spring-boot-docs}/how-to/webserver.html#howto.webserver.add-servlet-filter-listener.spring-bean[declare them as beans and configure them as part of your application].
17
17
18
+
In addition to the built-in filters, you can also create custom filters by implementing the standard
19
+
`javax.servlet.Filter` interface or extending one of Spring's convenient base classes:
20
+
21
+
* `GenericFilterBean` – Useful when you need access to Spring-managed beans or the application context.
22
+
* `OncePerRequestFilter` – Ensures a single execution per request, even for asynchronous or error dispatches.
23
+
24
+
These base classes simplify filter development and offer integration with Spring's `ApplicationContext`.
25
+
26
+
For example:
27
+
28
+
[source,java]
29
+
----
30
+
public class MyFilter extends OncePerRequestFilter {
0 commit comments