@ -127,6 +127,8 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@@ -127,6 +127,8 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@Nullable
privateFlashMapManagerflashMapManager;
privatebooleanpreferPathMatcher=false;
@Nullable
privatePathPatternParserpatternParser;
@ -317,8 +319,10 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@@ -317,8 +319,10 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@ -332,6 +336,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@@ -332,6 +336,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@ -468,15 +473,16 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@@ -468,15 +473,16 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
@ -157,7 +157,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
@@ -157,7 +157,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
@ -313,18 +313,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@@ -313,18 +313,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@ -334,10 +328,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@@ -334,10 +328,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@ -497,21 +493,29 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@@ -497,21 +493,29 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@ -532,18 +536,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@@ -532,18 +536,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@ -599,20 +592,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@@ -599,20 +592,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
@ -87,7 +88,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@@ -87,7 +88,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@ -127,43 +128,45 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@@ -127,43 +128,45 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@ -570,7 +573,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@@ -570,7 +573,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@ -579,6 +582,14 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@@ -579,6 +582,14 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
@ -102,7 +102,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
@@ -102,7 +102,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
@ -75,7 +75,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i
@@ -75,7 +75,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i
@ -92,6 +94,14 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
@@ -92,6 +94,14 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
@ -191,6 +201,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
@@ -191,6 +201,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
@ -181,6 +181,7 @@ public class DelegatingWebMvcConfigurationIntegrationTests {
@@ -181,6 +181,7 @@ public class DelegatingWebMvcConfigurationIntegrationTests {
@ -188,8 +189,16 @@ public class DelegatingWebMvcConfigurationIntegrationTests {
@@ -188,8 +189,16 @@ public class DelegatingWebMvcConfigurationIntegrationTests {
@ -197,5 +206,13 @@ public class DelegatingWebMvcConfigurationIntegrationTests {
@@ -197,5 +206,13 @@ public class DelegatingWebMvcConfigurationIntegrationTests {
@ -580,8 +580,8 @@ initialization parameters (`init-param` elements) to the Servlet declaration in
@@ -580,8 +580,8 @@ initialization parameters (`init-param` elements) to the Servlet declaration in
The Servlet API exposes the full request path as `requestURI` and further sub-divides it
into `contextPath`, `servletPath`, and `pathInfo` whose values vary depending on how a
Servlet is mapped. From these inputs, Spring MVC needs to determine the lookup path to
use for handler mapping, which is the path within the mapping of the `DispatcherServlet`
itself, excluding the `contextPath` and any `servletMapping` prefix, if present.
use for mapping handlers, which should exclude the `contextPath` and any `servletMapping`
prefix, if applicable.
The `servletPath` and `pathInfo` are decoded and that makes them impossible to compare
directly to the full `requestURI` in order to derive the lookupPath and that makes it
@ -611,15 +611,17 @@ encoded path which may not always work well. Furthermore, sometimes the
@@ -611,15 +611,17 @@ encoded path which may not always work well. Furthermore, sometimes the
`DispatcherServlet` needs to share the URL space with another Servlet and may need to
be mapped by prefix.
The above issues can be addressed more comprehensively by switching from `PathMatcher` to
the parsed `PathPattern` available in 5.3 or higher, see
<<mvc-ann-requestmapping-pattern-comparison>>. Unlike `AntPathMatcher` which needs
either the lookup path decoded or the controller mapping encoded, a parsed `PathPattern`
matches to a parsed representation of the path called `RequestPath`, one path segment
at a time. This allows decoding and sanitizing path segment values individually without
the risk of altering the structure of the path. Parsed `PathPattern` also supports
the use of `servletPath` prefix mapping as long as the prefix is kept simple and does
not have any characters that need to be encoded.
The above issues are addressed when using `PathPatternParser` and parsed patterns, as
an alternative to String path matching with `AntPathMatcher`. The `PathPatternParser` has
been available for use in Spring MVC from version 5.3, and is enabled by default from
version 6.0. Unlike `AntPathMatcher` which needs either the lookup path decoded or the
controller mapping encoded, a parsed `PathPattern` matches to a parsed representation
of the path called `RequestPath`, one path segment at a time. This allows decoding and
sanitizing path segment values individually without the risk of altering the structure
of the path. Parsed `PathPattern` also supports the use of `servletPath` prefix mapping
as long as a Servlet path mapping is used and the prefix is kept simple, i.e. it has no
encoded characters. For pattern syntax details and comparison, see
<<mvc-ann-requestmapping-pattern-comparison>>.
@ -1617,11 +1619,11 @@ filesystem, and other locations. It is less efficient and the String path input
@@ -1617,11 +1619,11 @@ filesystem, and other locations. It is less efficient and the String path input
challenge for dealing effectively with encoding and other issues with URLs.
`PathPattern` is the recommended solution for web applications and it is the only choice in
Spring WebFlux. Prior to version 5.3, `AntPathMatcher` was the only choice in Spring MVC
and continues to be the default. However `PathPattern` can be enabled in the
<<mvc-config-path-matching, MVC config>>.
Spring WebFlux. It was enabled for use in Spring MVC from version 5.3 and is enabled by
default from version 6.0. See <<mvc-config-path-matching, MVC config>> for
customizations of path matching options.
`PathPattern` supports the same pattern syntax as `AntPathMatcher`. In addition it also
`PathPattern` supports the same pattern syntax as `AntPathMatcher`. In addition, it also
supports the capturing pattern, e.g. `+{*spring}+`, for matching 0 or more path segments
at the end of a path. `PathPattern` also restricts the use of `+**+` for matching multiple
path segments such that it's only allowed at the end of a pattern. This eliminates many
@ -5997,9 +5999,7 @@ The following example shows how to customize path matching in Java configuration
@@ -5997,9 +5999,7 @@ The following example shows how to customize path matching in Java configuration
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
@ -6015,9 +6015,7 @@ The following example shows how to customize path matching in Java configuration
@@ -6015,9 +6015,7 @@ The following example shows how to customize path matching in Java configuration
class WebConfig : WebMvcConfigurer {
override fun configurePathMatch(configurer: PathMatchConfigurer) {
@ -6026,7 +6024,7 @@ The following example shows how to customize path matching in Java configuration
@@ -6026,7 +6024,7 @@ The following example shows how to customize path matching in Java configuration
}
----
The following example shows how to achieve the same configuration in XML:
The following example shows how to customize path matching in XML configuration: