Correct Servlet Path JavaDoc

Initially PathPatternRequestMatcher was designed to match relative
to the servlet path. However, this was changed to be relative to
the context path. This commit updates the documentation and removes
references to the servlet path other than in the context of setting
a basePath to remove boilerplate.

Issue gh-16430
This commit is contained in:
Josh Cummings 2025-07-07 11:27:39 -06:00
parent 8fb8e26c01
commit ea3ba62022
No known key found for this signature in database
GPG Key ID: 869B37A20E876129

View File

@ -38,8 +38,8 @@ import org.springframework.web.util.pattern.PathPatternParser;
* (that is, it should exclude any context path). * (that is, it should exclude any context path).
* *
* <p> * <p>
* You can provide the servlet path in {@link PathPatternRequestMatcher#servletPath} and * You can provide the servlet path in {@link PathPatternRequestMatcher.Builder#basePath}
* reuse for multiple matchers. * and reuse for multiple matchers.
* *
* <p> * <p>
* Note that the {@link org.springframework.web.servlet.HandlerMapping} that contains the * Note that the {@link org.springframework.web.servlet.HandlerMapping} that contains the
@ -55,14 +55,12 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
private final PathPattern pattern; private final PathPattern pattern;
private RequestMatcher servletPath = AnyRequestMatcher.INSTANCE;
private RequestMatcher method = AnyRequestMatcher.INSTANCE; private RequestMatcher method = AnyRequestMatcher.INSTANCE;
/** /**
* Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}. * Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}.
* <p> * <p>
* The {@code pattern} should be relative to the servlet path * The {@code pattern} should be relative to the context path
* </p> * </p>
* @param pattern the pattern used to match * @param pattern the pattern used to match
*/ */
@ -102,9 +100,6 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
*/ */
@Override @Override
public MatchResult matcher(HttpServletRequest request) { public MatchResult matcher(HttpServletRequest request) {
if (!this.servletPath.matches(request)) {
return MatchResult.notMatch();
}
if (!this.method.matches(request)) { if (!this.method.matches(request)) {
return MatchResult.notMatch(); return MatchResult.notMatch();
} }
@ -232,8 +227,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
* also be followed by {@code /**} to signify all URIs under a given path. * also be followed by {@code /**} to signify all URIs under a given path.
* *
* <p> * <p>
* These must be specified relative to any servlet path prefix (meaning you should * These must be specified relative to any context path prefix. A
* exclude the context path and any servlet path prefix in stating your pattern). * {@link #basePath} may be specified to reuse a common prefix, for example a
* servlet path.
* *
* <p> * <p>
* The following are valid patterns and their meaning * The following are valid patterns and their meaning
@ -266,8 +262,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
* also be followed by {@code /**} to signify all URIs under a given path. * also be followed by {@code /**} to signify all URIs under a given path.
* *
* <p> * <p>
* These must be specified relative to any servlet path prefix (meaning you should * These must be specified relative to any context path prefix. A
* exclude the context path and any servlet path prefix in stating your pattern). * {@link #basePath} may be specified to reuse a common prefix, for example a
* servlet path.
* *
* <p> * <p>
* The following are valid patterns and their meaning * The following are valid patterns and their meaning