From b74c10ba3a55a21678f3f4271e1a4bd1842adcae Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 27 Oct 2015 11:04:56 +0100 Subject: [PATCH] Document FilterRegistrationBeans specific default If a filter is registered in `web.xml` with no `dispatcher` element, the spec states that it should have the `REQUEST` dispatcher type only. As we are adding more dispatcher types by default, it can be surprising for users migrating from a `web.xml` based web app. The documentation has now an explicit note about this. Closes gh-2689 --- spring-boot-docs/src/main/asciidoc/howto.adoc | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index db43aac721..7f2f950afb 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -370,6 +370,27 @@ In the case of `Filters` and `Servlets` you can also add mappings and init param adding a `FilterRegistrationBean` or `ServletRegistrationBean` instead of or as well as the underlying component. +[NOTE] +==== +If no `dispatcherType` is specified on a filter registration, it will match +`FORWARD`,`INCLUDE` and `REQUEST`. If async has been enabled, it will match `ASYNC` as +well. + +If you are migrating a filter that has no `dispatcher` element in `web.xml` you will +need to specify a `dispatcherType` yourself: + +[source,java,indent=0,subs="verbatim,quotes,attributes"] +---- + @Bean + public FilterRegistrationBean myFilterRegistration() { + FilterRegistrationBean registration = new FilterRegistrationBean(); + registration.setDispatcherTypes(DispatcherType.REQUEST); + .... + + return registration; + } +---- +==== [[howto-disable-registration-of-a-servlet-or-filter]]