@@ -28875,6 +28875,26 @@ configuration. For more information on placeholders, see the javadocs of the
28875
28875
`PropertyPlaceholderConfigurer` class.
28876
28876
28877
28877
28878
+
28879
+ [[mvc-ann-requestmapping-uri-vars-and-file-extensions]]
28880
+ ===== URI Variables and Suffix Patterns Matching
28881
+ By default Spring MVC automatically performs `".*"` suffix pattern matching so
28882
+ that a controller mapped to `/person` is also implicitly mapped to `/person.*`.
28883
+ This allows indicating content types via file extensions, e.g. `/person.pdf`,
28884
+ `/person.xml`, etc. A common pitfall however is when the last path segment of the
28885
+ mapping is a URI variable, e.g. `/person/{id}`. While a request for `/person/1.json`
28886
+ would correctly result in path variable id=1 and extension ".json", when the id
28887
+ naturally contains a dot, e.g. `/person/
[email protected] ` the result does not match
28888
+ expectations. Clearly here ".com" is not a file extension.
28889
+
28890
+ The proper way to address this is to configure Spring MVC to only do suffix pattern
28891
+ matching against file extensions registered for content negotiation purposes.
28892
+ For more on this, first see <<mvc-config-content-negotiation>> and then
28893
+ <<mvc-config-path-matching>> showing how to enable suffix pattern matching
28894
+ along with how to use registered suffix patterns only.
28895
+
28896
+
28897
+
28878
28898
[[mvc-ann-matrix-variables]]
28879
28899
===== Matrix Variables
28880
28900
The URI specification http://tools.ietf.org/html/rfc3986#section-3.3[RFC 3986] defines
@@ -32572,8 +32592,10 @@ An example of enabling pattern match features and using custom matchers, in Java
32572
32592
32573
32593
@Override
32574
32594
public void configurePathMatch(PathMatchConfigurer configurer) {
32575
- configurer.setUseSuffixPatternMatch(true)
32595
+ configurer
32596
+ .setUseSuffixPatternMatch(true)
32576
32597
.setUseTrailingSlashMatch(false)
32598
+ .setUseRegisteredSuffixPatternMatch(true)
32577
32599
.setPathMatcher(antPathMatcher())
32578
32600
.setUrlPathHelper(urlPathHelper());
32579
32601
}
@@ -32603,6 +32625,7 @@ And the same in XML, use the `<mvc:path-matching>` element:
32603
32625
<mvc:path-matching
32604
32626
suffix-pattern="true"
32605
32627
trailing-slash="false"
32628
+ registered-suffixes-only="true"
32606
32629
path-helper="pathHelper"
32607
32630
path-matcher="pathMatcher" />
32608
32631
</mvc:annotation-driven>
0 commit comments