Correct documentation of default path matching strategy

Closes gh-32557
This commit is contained in:
Andy Wilkinson 2023-08-08 11:48:04 +01:00
parent 35d3cdbe74
commit e7203e31c8
1 changed files with 8 additions and 13 deletions

View File

@ -255,27 +255,22 @@ Alternatively, rather than open all suffix patterns, it is more secure to only s
use-registered-suffix-pattern: true use-registered-suffix-pattern: true
---- ----
As of Spring Framework 5.3, Spring MVC supports several implementation strategies for matching request paths to Controller handlers. As of Spring Framework 5.3, Spring MVC supports two strategies for matching request paths to controllers.
It was previously only supporting the `AntPathMatcher` strategy, but it now also offers `PathPatternParser`. By default, Spring Boot uses the `PathPatternParser` strategy.
Spring Boot now provides a configuration property to choose and opt in the new strategy: `PathPatternParser` is an https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc[optimized implementation] but comes with some restrictions compared to the `AntPathMatcher` strategy.
`PathPatternParser` restricts usage of {spring-framework-docs}/web.html#mvc-ann-requestmapping-uri-templates[some path patterns variants].
It is also incompatible with suffix pattern matching (configprop:spring.mvc.pathmatch.use-suffix-pattern[deprecated], configprop:spring.mvc.pathmatch.use-registered-suffix-pattern[deprecated]) and configuring the `DispatcherServlet` with a path prefix (configprop:spring.mvc.servlet.path[]).
The strategy can be configured using the configprop:spring.mvc.pathmatch.matching-strategy[] configuration property, as shown in the following example:
[source,yaml,indent=0,subs="verbatim",configprops,configblocks] [source,yaml,indent=0,subs="verbatim",configprops,configblocks]
---- ----
spring: spring:
mvc: mvc:
pathmatch: pathmatch:
matching-strategy: "path-pattern-parser" matching-strategy: "ant-path-matcher"
---- ----
For more details on why you should consider this new implementation, see 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[]).
By default, Spring MVC will send a 404 Not Found error response if a handler is not found for a request. By default, Spring MVC will send a 404 Not Found error response if a handler is not found for a request.
To have a `NoHandlerFoundException` thrown instead, set configprop:spring.mvc.throw-exception-if-no-handler-found to `true`. To have a `NoHandlerFoundException` thrown instead, set configprop:spring.mvc.throw-exception-if-no-handler-found to `true`.
Note that, by default, the <<web#web.servlet.spring-mvc.static-content, serving of static content>> is mapped to `+/**+` and will, therefore, provide a handler for all requests. Note that, by default, the <<web#web.servlet.spring-mvc.static-content, serving of static content>> is mapped to `+/**+` and will, therefore, provide a handler for all requests.