Add option to configure PathPatternParser
As of Spring Framework 5.3, it is now possible to use `PathPatternParser` to parse and match request mapping path patterns, as an alternative to the current default `AntPathMatcher`. This new implementation has been used for a while in Spring WebFlux and it’s been designed for consistency and performance. This commit introduces a new configuration property for opting-in this new variant: `spring.mvc.pathmatch.matching-strategy=path_pattern_parser` The default option is still `ant_path_matcher` for now, but we might change the default in future versions since Spring Framework considers it the best choice for modern applications. There are several behavior differences with this new variant: * double wildcards `"**"` are rejected when used in the middle patterns, this is only allowed as the last matching segment in a pattern. * it is incompatible with some path matching options, like suffix-pattern, registered-suffix-pattern or configuring a Servlet prefix on the `DispatcherServlet` (`spring.mvc.servlet.path=/test`) This commit introduces two `FailureAnalyzer` implementations to guide developers when facing those issues. Closes gh-21694
This commit is contained in:
@@ -2441,6 +2441,24 @@ Alternatively, rather than open all suffix patterns, it's more secure to just su
|
||||
# spring.mvc.contentnegotiation.media-types.adoc=text/asciidoc
|
||||
----
|
||||
|
||||
As of Spring Framework 5.3, Spring MVC supports several implementation strategies for matching request paths to Controller handlers.
|
||||
It was previously only supporting the `AntPathMatcher` strategy, but it now also offers `PathPatternParser`.
|
||||
Spring Boot now provides a configuration property to choose and opt in the new strategy:
|
||||
|
||||
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
spring.mvc.pathmatch.matching-strategy=path_pattern_parser
|
||||
----
|
||||
|
||||
For more details on why you should consider this new implementation, please check out the
|
||||
https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc[dedicated blog post].
|
||||
|
||||
NOTE: `PathPatternParser` is an optimized implementation but restricts usage of
|
||||
{spring-framework-docs}/web.html#mvc-ann-requestmapping-uri-templates[some path patterns variants]
|
||||
and is incompatible with suffix pattern matching (configprop:spring.mvc.pathmatch.use-suffix-pattern[deprecated],
|
||||
configprop:spring.mvc.pathmatch.use-registered-suffix-pattern[deprecated]) or mapping the `DispatcherServlet`
|
||||
with a Servlet prefix (configprop:spring.mvc.servlet.path[]).
|
||||
|
||||
|
||||
|
||||
[[boot-features-spring-mvc-web-binding-initializer]]
|
||||
|
||||
Reference in New Issue
Block a user