Skip to content

Commit 3737637

Browse files
committed
Deprecate use of PathMatcher and UrlPathHelper in web
Closes gh-34018
1 parent 41a9db3 commit 3737637

File tree

56 files changed

+352
-44
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+352
-44
lines changed

framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ Kotlin::
157157
----
158158
======
159159

160-
Note that you need to enable the use of matrix variables. In the MVC Java configuration,
161-
you need to set a `UrlPathHelper` with `removeSemicolonContent=false` through
162-
xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching]. In the MVC XML namespace, you can set
160+
Note that you need to enable the use of matrix variables. In the MVC XML namespace, you can set
163161
`<mvc:annotation-driven enable-matrix-variables="true"/>`.
164162

165163

spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ public RouterFunctionMockMvcBuilder setAsyncRequestTimeout(long timeout) {
188188
}
189189

190190
/**
191-
* Enable URL path matching with parsed
192-
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}
193-
* instead of String pattern matching with a {@link org.springframework.util.PathMatcher}.
191+
* Configure the parser to use for
192+
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}.
193+
* <p>By default, this is a default instance of {@link PathPatternParser}.
194194
* @param parser the parser to use
195195
*/
196196
public RouterFunctionMockMvcBuilder setPatternParser(@Nullable PathPatternParser parser) {

spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.format.support.FormattingConversionService;
3838
import org.springframework.http.converter.HttpMessageConverter;
3939
import org.springframework.mock.web.MockServletContext;
40+
import org.springframework.util.PathMatcher;
4041
import org.springframework.util.PropertyPlaceholderHelper;
4142
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
4243
import org.springframework.util.StringValueResolver;
@@ -297,9 +298,9 @@ public StandaloneMockMvcBuilder setFlashMapManager(FlashMapManager flashMapManag
297298
}
298299

299300
/**
300-
* Enable URL path matching with parsed
301-
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}
302-
* instead of String pattern matching with a {@link org.springframework.util.PathMatcher}.
301+
* Configure the parser to use for
302+
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}.
303+
* <p>By default, this is a default instance of {@link PathPatternParser}.
303304
* @param parser the parser to use
304305
* @since 5.3
305306
*/
@@ -313,7 +314,11 @@ public StandaloneMockMvcBuilder setPatternParser(@Nullable PathPatternParser par
313314
* Set if ";" (semicolon) content should be stripped from the request URI. The value,
314315
* if provided, is in turn set on
315316
* {@link org.springframework.web.util.UrlPathHelper#setRemoveSemicolonContent(boolean)}.
317+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
318+
* for use at runtime in web modules in favor of parsed patterns with
319+
* {@link PathPatternParser}.
316320
*/
321+
@Deprecated(since = "7.0", forRemoval = true)
317322
public StandaloneMockMvcBuilder setRemoveSemicolonContent(boolean removeSemicolonContent) {
318323
this.removeSemicolonContent = removeSemicolonContent;
319324
return this;
@@ -428,6 +433,7 @@ protected Map<String, Object> extendMvcSingletons(@Nullable ServletContext servl
428433
/** Using the MVC Java configuration as the starting point for the "standalone" setup. */
429434
private class StandaloneConfiguration extends WebMvcConfigurationSupport {
430435

436+
@SuppressWarnings("removal")
431437
public RequestMappingHandlerMapping getHandlerMapping(
432438
FormattingConversionService mvcConversionService,
433439
ResourceUrlProvider mvcResourceUrlProvider) {

spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/EncodedUriTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,6 +105,7 @@ String getCircuit(@PathVariable String id, Model model) {
105105
@Component
106106
static class HandlerMappingConfigurer implements BeanPostProcessor, PriorityOrdered {
107107

108+
@SuppressWarnings("removal")
108109
@Override
109110
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
110111
if (bean instanceof RequestMappingHandlerMapping requestMappingHandlerMapping) {

spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -141,7 +141,11 @@ private void initUrlPathHelper() {
141141
* parsed {@code PathPatterns} are used instead.
142142
* For further details on that, see {@link #setAllowInitLookupPath(boolean)}.
143143
* <p>By default this is {@link UrlPathHelper#defaultInstance}.
144+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
145+
* for use at runtime in web modules in favor of parsed patterns with
146+
* {@link PathPatternParser}.
144147
*/
148+
@Deprecated(since = "7.0", forRemoval = true)
145149
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
146150
Assert.notNull(urlPathHelper, "UrlPathHelper must not be null");
147151
this.urlPathHelper = urlPathHelper;
@@ -167,7 +171,11 @@ public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
167171
* @param allowInitLookupPath whether to disable lazy initialization
168172
* and fail if not already resolved
169173
* @since 5.3
174+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
175+
* for use at runtime in web modules in favor of parsed patterns with
176+
* {@link PathPatternParser}.
170177
*/
178+
@Deprecated(since = "7.0", forRemoval = true)
171179
public void setAllowInitLookupPath(boolean allowInitLookupPath) {
172180
this.allowInitLookupPath = allowInitLookupPath;
173181
}
@@ -194,7 +202,11 @@ public void setLookupPathAttributeName(String name) {
194202
* String pattern matching even when a
195203
* {@link ServletRequestPathUtils#parseAndCache parsed} {@code RequestPath}
196204
* is available.
205+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
206+
* for use at runtime in web modules in favor of parsed patterns with
207+
* {@link PathPatternParser}.
197208
*/
209+
@Deprecated(since = "7.0", forRemoval = true)
198210
public void setPathMatcher(PathMatcher pathMatcher) {
199211
this.pathMatcher = pathMatcher;
200212
}

spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void unmodifiableConfigurationsMap() {
7171
.isThrownBy(() -> source.getCorsConfigurations().put("/**", new CorsConfiguration()));
7272
}
7373

74+
@SuppressWarnings("removal")
7475
@Test
7576
void allowInitLookupPath() {
7677
CorsConfiguration config = new CorsConfiguration();

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,9 @@
2929
import org.springframework.web.servlet.HandlerInterceptor;
3030
import org.springframework.web.servlet.handler.MappedInterceptor;
3131
import org.springframework.web.util.ServletRequestPathUtils;
32+
import org.springframework.web.util.UrlPathHelper;
3233
import org.springframework.web.util.pattern.PathPattern;
34+
import org.springframework.web.util.pattern.PathPatternParser;
3335

3436
/**
3537
* Assists with the creation of a {@link MappedInterceptor}.
@@ -114,7 +116,11 @@ public InterceptorRegistration excludePathPatterns(List<String> patterns) {
114116
* String pattern matching even when a
115117
* {@link ServletRequestPathUtils#parseAndCache parsed} {@code RequestPath}
116118
* is available.
119+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
120+
* for use at runtime in web modules in favor of parsed patterns with
121+
* {@link PathPatternParser}.
117122
*/
123+
@Deprecated(since = "7.0", forRemoval = true)
118124
public InterceptorRegistration pathMatcher(PathMatcher pathMatcher) {
119125
this.pathMatcher = pathMatcher;
120126
return this;
@@ -140,6 +146,7 @@ protected int getOrder() {
140146
* Build the underlying interceptor. If URL patterns are provided, the returned
141147
* type is {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
142148
*/
149+
@SuppressWarnings("removal")
143150
protected Object getInterceptor() {
144151

145152
if (this.includePatterns == null && this.excludePatterns == null) {

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ public class PathMatchConfigurer {
6565
* Set the {@link PathPatternParser} to parse {@link PathPattern patterns}
6666
* with for URL path matching. Parsed patterns provide a more modern and
6767
* efficient alternative to String path matching via {@link AntPathMatcher}.
68-
* <p><strong>Note:</strong> This property is mutually exclusive with the
69-
* following other, {@code AntPathMatcher} related properties:
70-
* <ul>
71-
* <li>{@link #setUrlPathHelper(UrlPathHelper)}
72-
* <li>{@link #setPathMatcher(PathMatcher)}
73-
* </ul>
7468
* <p>By default, as of 6.0, a {@link PathPatternParser} with default
7569
* settings is used, which enables parsed {@link PathPattern patterns}.
7670
* Set this property to {@code null} to fall back on String path matching via
@@ -110,9 +104,13 @@ public PathMatchConfigurer addPathPrefix(String prefix, Predicate<Class<?>> pred
110104
* {@link #setPatternParser(PathPatternParser)}. If set, it enables use of
111105
* String path matching, unless a {@code PathPatternParser} is also
112106
* explicitly set in which case this property is ignored.
113-
* <p>By default this is an instance of {@link UrlPathHelper} with default
107+
* <p>By default, this is an instance of {@link UrlPathHelper} with default
114108
* settings.
109+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
110+
* for use at runtime in web modules in favor of parsed patterns with
111+
* {@link PathPatternParser}.
115112
*/
113+
@Deprecated(since = "7.0", forRemoval = true)
116114
public PathMatchConfigurer setUrlPathHelper(UrlPathHelper urlPathHelper) {
117115
this.urlPathHelper = urlPathHelper;
118116
this.preferPathMatcher = true;
@@ -125,9 +123,12 @@ public PathMatchConfigurer setUrlPathHelper(UrlPathHelper urlPathHelper) {
125123
* {@link #setPatternParser(PathPatternParser)}. If set, it enables use of
126124
* String path matching, unless a {@code PathPatternParser} is also
127125
* explicitly set in which case this property is ignored.
128-
* <p>By default this is an instance of {@link AntPathMatcher} with default
126+
* <p>By default, this is an instance of {@link AntPathMatcher} with default
129127
* settings.
128+
* @deprecated use of {@link PathMatcher} is deprecated for use at runtime
129+
* in web modules in favor of parsed patterns with {@link PathPatternParser}.
130130
*/
131+
@Deprecated(since = "7.0", forRemoval = true)
131132
public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher) {
132133
this.pathMatcher = pathMatcher;
133134
this.preferPathMatcher = true;
@@ -143,7 +144,10 @@ public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher) {
143144
* {@link PathMatcher} related option is explicitly set.
144145
* </ul>
145146
* @since 6.0
147+
* @deprecated use of {@link PathMatcher} is deprecated for use at runtime
148+
* in web modules in favor of parsed patterns with {@link PathPatternParser}.
146149
*/
150+
@Deprecated(since = "7.0", forRemoval = true)
147151
protected boolean preferPathMatcher() {
148152
return (this.patternParser == null && this.preferPathMatcher);
149153
}
@@ -160,18 +164,24 @@ protected boolean preferPathMatcher() {
160164
return this.pathPrefixes;
161165
}
162166

167+
@Deprecated(since = "7.0", forRemoval = true)
163168
public @Nullable UrlPathHelper getUrlPathHelper() {
164169
return this.urlPathHelper;
165170
}
166171

172+
@Deprecated(since = "7.0", forRemoval = true)
167173
public @Nullable PathMatcher getPathMatcher() {
168174
return this.pathMatcher;
169175
}
170176

171177
/**
172178
* Return the configured UrlPathHelper or a default, shared instance otherwise.
173179
* @since 5.3
180+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
181+
* for use at runtime in web modules in favor of parsed patterns with
182+
* {@link PathPatternParser}.
174183
*/
184+
@Deprecated(since = "7.0", forRemoval = true)
175185
protected UrlPathHelper getUrlPathHelperOrDefault() {
176186
if (this.urlPathHelper != null) {
177187
return this.urlPathHelper;
@@ -185,7 +195,10 @@ protected UrlPathHelper getUrlPathHelperOrDefault() {
185195
/**
186196
* Return the configured PathMatcher or a default, shared instance otherwise.
187197
* @since 5.3
198+
* @deprecated use of {@link PathMatcher} is deprecated for use at runtime
199+
* in web modules in favor of parsed patterns with {@link PathPatternParser}.
188200
*/
201+
@Deprecated(since = "7.0", forRemoval = true)
189202
protected PathMatcher getPathMatcherOrDefault() {
190203
if (this.pathMatcher != null) {
191204
return this.pathMatcher;

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletCon
100100
* {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)}
101101
* that also accepts the {@link UrlPathHelper} used for mapping requests to static resources.
102102
* @since 4.3.13
103+
* @deprecated in favor of
104+
* {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)}
103105
*/
106+
@Deprecated(since = "7.0", forRemoval = true)
104107
public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext,
105108
@Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) {
106109

@@ -167,6 +170,7 @@ public ResourceHandlerRegistry setOrder(int order) {
167170
return new SimpleUrlHandlerMapping(urlMap, this.order);
168171
}
169172

173+
@SuppressWarnings("removal")
170174
private ResourceHttpRequestHandler getRequestHandler(ResourceHandlerRegistration registration) {
171175
ResourceHttpRequestHandler handler = registration.getRequestHandler();
172176
if (this.pathHelper != null) {

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,12 @@ public PathPatternParser mvcPatternParser() {
391391
* <p><b>Note:</b> This is only used when parsed patterns are not
392392
* {@link PathMatchConfigurer#setPatternParser enabled}.
393393
* @since 4.1
394+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
395+
* for use at runtime in web modules in favor of parsed patterns with
396+
* {@link PathPatternParser}.
394397
*/
398+
@SuppressWarnings("removal")
399+
@Deprecated(since = "7.0", forRemoval = true)
395400
@Bean
396401
public UrlPathHelper mvcUrlPathHelper() {
397402
return getPathMatchConfigurer().getUrlPathHelperOrDefault();
@@ -404,7 +409,12 @@ public UrlPathHelper mvcUrlPathHelper() {
404409
* <p><b>Note:</b> This is only used when parsed patterns are not
405410
* {@link PathMatchConfigurer#setPatternParser enabled}.
406411
* @since 4.1
412+
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
413+
* for use at runtime in web modules in favor of parsed patterns with
414+
* {@link PathPatternParser}.
407415
*/
416+
@SuppressWarnings("removal")
417+
@Deprecated(since = "7.0", forRemoval = true)
408418
@Bean
409419
public PathMatcher mvcPathMatcher() {
410420
return getPathMatchConfigurer().getPathMatcherOrDefault();
@@ -474,6 +484,7 @@ protected void configureContentNegotiation(ContentNegotiationConfigurer configur
474484
return mapping;
475485
}
476486

487+
@SuppressWarnings("removal")
477488
private void initHandlerMapping(
478489
@Nullable AbstractHandlerMapping mapping, FormattingConversionService conversionService,
479490
ResourceUrlProvider resourceUrlProvider) {
@@ -554,6 +565,7 @@ public RouterFunctionMapping routerFunctionMapping(
554565
* resource handlers. To configure resource handling, override
555566
* {@link #addResourceHandlers}.
556567
*/
568+
@SuppressWarnings("removal")
557569
@Bean
558570
public @Nullable HandlerMapping resourceHandlerMapping(
559571
@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager,
@@ -585,6 +597,7 @@ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
585597
* A {@link ResourceUrlProvider} bean for use with the MVC dispatcher.
586598
* @since 4.1
587599
*/
600+
@SuppressWarnings("removal")
588601
@Bean
589602
public ResourceUrlProvider mvcResourceUrlProvider() {
590603
ResourceUrlProvider urlProvider = new ResourceUrlProvider();

spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ private void setAttributes(HttpServletRequest servletRequest, ServerRequest requ
222222
servletRequest.setAttribute(RouterFunctions.REQUEST_ATTRIBUTE, request);
223223
}
224224

225+
@SuppressWarnings("removal")
226+
@Deprecated(since = "7.0", forRemoval = true)
225227
@Override
226228
public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) {
227229
throw new UnsupportedOperationException("This HandlerMapping uses PathPatterns");

0 commit comments

Comments
 (0)