Skip to content

Commit e7203e3

Browse files
committed
Correct documentation of default path matching strategy
Closes gh-32557
1 parent 35d3cdb commit e7203e3

File tree

1 file changed

+8
-13
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/asciidoc/web

1 file changed

+8
-13
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,27 +255,22 @@ Alternatively, rather than open all suffix patterns, it is more secure to only s
255255
use-registered-suffix-pattern: true
256256
----
257257

258-
As of Spring Framework 5.3, Spring MVC supports several implementation strategies for matching request paths to Controller handlers.
259-
It was previously only supporting the `AntPathMatcher` strategy, but it now also offers `PathPatternParser`.
260-
Spring Boot now provides a configuration property to choose and opt in the new strategy:
258+
As of Spring Framework 5.3, Spring MVC supports two strategies for matching request paths to controllers.
259+
By default, Spring Boot uses the `PathPatternParser` strategy.
260+
`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.
261+
`PathPatternParser` restricts usage of {spring-framework-docs}/web.html#mvc-ann-requestmapping-uri-templates[some path patterns variants].
262+
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[]).
263+
264+
The strategy can be configured using the configprop:spring.mvc.pathmatch.matching-strategy[] configuration property, as shown in the following example:
261265

262266
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
263267
----
264268
spring:
265269
mvc:
266270
pathmatch:
267-
matching-strategy: "path-pattern-parser"
271+
matching-strategy: "ant-path-matcher"
268272
----
269273

270-
For more details on why you should consider this new implementation, see the
271-
https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc[dedicated blog post].
272-
273-
NOTE: `PathPatternParser` is an optimized implementation but restricts usage of
274-
{spring-framework-docs}/web.html#mvc-ann-requestmapping-uri-templates[some path patterns variants]
275-
and is incompatible with suffix pattern matching (configprop:spring.mvc.pathmatch.use-suffix-pattern[deprecated],
276-
configprop:spring.mvc.pathmatch.use-registered-suffix-pattern[deprecated]) or mapping the `DispatcherServlet`
277-
with a servlet prefix (configprop:spring.mvc.servlet.path[]).
278-
279274
By default, Spring MVC will send a 404 Not Found error response if a handler is not found for a request.
280275
To have a `NoHandlerFoundException` thrown instead, set configprop:spring.mvc.throw-exception-if-no-handler-found to `true`.
281276
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.

0 commit comments

Comments
 (0)