From e7203e31c8309884fd5158fbca0890ea4ace887d Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 8 Aug 2023 11:48:04 +0100 Subject: [PATCH] Correct documentation of default path matching strategy Closes gh-32557 --- .../src/docs/asciidoc/web/servlet.adoc | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc index 925a8c57ac..879609d466 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc @@ -255,27 +255,22 @@ Alternatively, rather than open all suffix patterns, it is more secure to only s use-registered-suffix-pattern: true ---- -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: +As of Spring Framework 5.3, Spring MVC supports two strategies for matching request paths to controllers. +By default, Spring Boot uses the `PathPatternParser` 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] ---- spring: mvc: 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. To have a `NoHandlerFoundException` thrown instead, set configprop:spring.mvc.throw-exception-if-no-handler-found to `true`. Note that, by default, the <> is mapped to `+/**+` and will, therefore, provide a handler for all requests.