@@ -55,7 +55,7 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
5555
5656 private final PathPattern pattern ;
5757
58- private RequestMatcher method = AnyRequestMatcher . INSTANCE ;
58+ private final RequestMatcher method ;
5959
6060 /**
6161 * Creates a {@link PathPatternRequestMatcher} that uses the provided {@code pattern}.
@@ -64,8 +64,9 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
6464 * </p>
6565 * @param pattern the pattern used to match
6666 */
67- private PathPatternRequestMatcher (PathPattern pattern ) {
67+ private PathPatternRequestMatcher (PathPattern pattern , RequestMatcher method ) {
6868 this .pattern = pattern ;
69+ this .method = method ;
6970 }
7071
7172 /**
@@ -108,10 +109,6 @@ public MatchResult matcher(HttpServletRequest request) {
108109 return (info != null ) ? MatchResult .match (info .getUriVariables ()) : MatchResult .notMatch ();
109110 }
110111
111- void setMethod (RequestMatcher method ) {
112- this .method = method ;
113- }
114-
115112 private PathContainer getPathContainer (HttpServletRequest request ) {
116113 RequestPath path ;
117114 if (ServletRequestPathUtils .hasParsedRequestPath (request )) {
@@ -286,11 +283,8 @@ public PathPatternRequestMatcher matcher(@Nullable HttpMethod method, String pat
286283 Assert .notNull (path , "pattern cannot be null" );
287284 Assert .isTrue (path .startsWith ("/" ), "pattern must start with a /" );
288285 PathPattern pathPattern = this .parser .parse (this .basePath + path );
289- PathPatternRequestMatcher requestMatcher = new PathPatternRequestMatcher (pathPattern );
290- if (method != null ) {
291- requestMatcher .setMethod (new HttpMethodRequestMatcher (method ));
292- }
293- return requestMatcher ;
286+ return new PathPatternRequestMatcher (pathPattern ,
287+ (method != null ) ? new HttpMethodRequestMatcher (method ) : AnyRequestMatcher .INSTANCE );
294288 }
295289
296290 }
0 commit comments