diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java
index 6a868c302d..9aa03935f9 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -358,7 +358,10 @@ public interface MockMvcWebTestClient {
* Whether to match trailing slashes.
*
This is delegated to
* {@link StandaloneMockMvcBuilder#setUseTrailingSlashPatternMatch(boolean)}.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
ControllerSpec useTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch);
/**
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java
index d935bd8b1b..b7b1f4d448 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -152,6 +152,7 @@ class StandaloneMockMvcSpec extends AbstractMockMvcServerSpecThe default value is {@code true}.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
public StandaloneMockMvcBuilder setUseTrailingSlashPatternMatch(boolean useTrailingSlashPatternMatch) {
this.useTrailingSlashPatternMatch = useTrailingSlashPatternMatch;
return this;
diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java
index add9394203..fd4679c6aa 100644
--- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java
+++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/spr/FormContentTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public class FormContentTests {
@RestController
private static class Spr15753Controller {
- @PutMapping
+ @PutMapping("/")
public String test(Data d) {
return String.format("d1:%s, d2:%s.", d.getD1(), d.getD2());
}
diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java
index 956aafe34a..77f7e1191c 100644
--- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java
+++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -150,6 +150,7 @@ public class PathPattern implements Comparable {
private boolean catchAll = false;
+ @SuppressWarnings("deprecation")
PathPattern(String patternText, PathPatternParser parser, @Nullable PathElement head) {
this.patternString = patternText;
this.parser = parser;
diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java
index 12488ffa4b..cc3e3a7950 100644
--- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java
+++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import org.springframework.http.server.PathContainer;
*/
public class PathPatternParser {
- private boolean matchOptionalTrailingSeparator = true;
+ private boolean matchOptionalTrailingSeparator = false;
private boolean caseSensitive = true;
@@ -48,15 +48,22 @@ public class PathPatternParser {
* will also match request paths with a trailing slash. If set to
* {@code false} a {@code PathPattern} will only match request paths with
* a trailing slash.
- * The default is {@code true}.
+ *
The default was changed in 6.0 from {@code true} to {@code false} in
+ * order to support the deprecation of the property.
+ * @deprecated transparent support for trailing slashes is deprecated as of
+ * 6.0 in favor of configuring explicit redirects through a proxy,
+ * Servlet/web filter, or a controller.
*/
+ @Deprecated
public void setMatchOptionalTrailingSeparator(boolean matchOptionalTrailingSeparator) {
this.matchOptionalTrailingSeparator = matchOptionalTrailingSeparator;
}
/**
* Whether optional trailing slashing match is enabled.
+ * @deprecated as of 6.0 together with {@link #setMatchOptionalTrailingSeparator(boolean)}.
*/
+ @Deprecated
public boolean isMatchOptionalTrailingSeparator() {
return this.matchOptionalTrailingSeparator;
}
diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java
index 669f527235..740b61152d 100644
--- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java
+++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,6 @@ public class PathPatternRouteMatcher implements RouteMatcher {
public PathPatternRouteMatcher() {
this.parser = new PathPatternParser();
this.parser.setPathOptions(PathContainer.Options.MESSAGE_ROUTE);
- this.parser.setMatchOptionalTrailingSeparator(false);
}
/**
diff --git a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java
index 0587fc4a8b..7a8f6e2e9c 100644
--- a/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java
+++ b/spring-web/src/test/java/org/springframework/web/util/pattern/PathPatternTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,6 +99,7 @@ public class PathPatternTests {
assertThat(pp.matches(toPathContainer(path))).isFalse();
}
+ @SuppressWarnings("deprecation")
@Test
public void optionalTrailingSeparators() {
PathPattern pp;
@@ -438,6 +439,7 @@ public class PathPatternTests {
checkCapture("///{foo}///bar", "///one///bar", "foo", "one");
}
+ @SuppressWarnings("deprecation")
@Test
public void wildcards() {
checkMatches("/*/bar", "/foo/bar");
@@ -725,6 +727,7 @@ public class PathPatternTests {
}
@Test
+ @SuppressWarnings("deprecation")
public void extractUriTemplateVariables_spr15264() {
PathPattern pp;
pp = new PathPatternParser().parse("/{foo}");
@@ -1145,6 +1148,7 @@ public class PathPatternTests {
return parse(pattern).matchAndExtract(PathPatternTests.toPathContainer(path));
}
+ @SuppressWarnings("deprecation")
private PathPattern parse(String path) {
PathPatternParser pp = new PathPatternParser();
pp.setMatchOptionalTrailingSeparator(true);
@@ -1158,6 +1162,7 @@ public class PathPatternTests {
return PathContainer.parsePath(path);
}
+ @SuppressWarnings("deprecation")
private void checkMatches(String uriTemplate, String path) {
PathPatternParser parser = new PathPatternParser();
parser.setMatchOptionalTrailingSeparator(true);
diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java
index 7f9988916e..ec83d837c6 100644
--- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java
+++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.function.Predicate;
import org.springframework.lang.Nullable;
+import org.springframework.web.util.pattern.PathPatternParser;
/**
* Assist with configuring {@code HandlerMapping}'s with path matching options.
@@ -55,8 +56,12 @@ public class PathMatchConfigurer {
/**
* Whether to match to URLs irrespective of the presence of a trailing slash.
* If enabled a method mapped to "/users" also matches to "/users/".
- *
The default value is {@code true}.
+ *
The default was changed in 6.0 from {@code true} to {@code false} in
+ * order to support the deprecation of the property.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) {
this.trailingSlashMatch = trailingSlashMatch;
return this;
@@ -83,6 +88,7 @@ public class PathMatchConfigurer {
@Nullable
+ @Deprecated
protected Boolean isUseTrailingSlashMatch() {
return this.trailingSlashMatch;
}
diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java
index 1de7d9428e..12baba94d9 100644
--- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java
+++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/WebFluxConfigurationSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -142,6 +142,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
return mapping;
}
+ @SuppressWarnings("deprecation")
private void configureAbstractHandlerMapping(AbstractHandlerMapping mapping, PathMatchConfigurer configurer) {
mapping.setCorsConfigurations(getCorsConfigurations());
Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java
index 9176b731aa..ef43e4b3d4 100644
--- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java
+++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
LogDelegateFactory.getHiddenLog(HandlerMapping.class.getName() + ".Mappings");
- private final PathPatternParser patternParser;
+ private final PathPatternParser patternParser = new PathPatternParser();
@Nullable
private CorsConfigurationSource corsConfigurationSource;
@@ -71,11 +71,6 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
private String beanName;
- public AbstractHandlerMapping() {
- this.patternParser = new PathPatternParser();
- }
-
-
/**
* Shortcut method for setting the same property on the underlying pattern
* parser in use. For more details see:
@@ -98,7 +93,12 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport
*
{@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)} --
* the trailing slash option, including its default value.
*
+ * The default was changed in 6.0 from {@code true} to {@code false} in
+ * order to support the deprecation of the property.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
public void setUseTrailingSlashMatch(boolean trailingSlashMatch) {
this.patternParser.setMatchOptionalTrailingSeparator(trailingSlashMatch);
}
diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
index 5558e13ef3..13542696a3 100644
--- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
+++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,7 +110,7 @@ public class WebFluxConfigurationSupportTests {
PathPatternParser patternParser = mapping.getPathPatternParser();
assertThat(patternParser).isNotNull();
boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
- assertThat(matchOptionalTrailingSlash).isTrue();
+ assertThat(matchOptionalTrailingSlash).isFalse();
name = "webFluxContentTypeResolver";
RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
@@ -124,18 +124,11 @@ public class WebFluxConfigurationSupportTests {
@Test
public void customPathMatchConfig() {
ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
- final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
- ReflectionUtils.makeAccessible(field);
String name = "requestMappingHandlerMapping";
RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
assertThat(mapping).isNotNull();
- PathPatternParser patternParser = mapping.getPathPatternParser();
- assertThat(patternParser).isNotNull();
- boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
- assertThat(matchOptionalTrailingSlash).isFalse();
-
Map map = mapping.getHandlerMethods();
assertThat(map.size()).isEqualTo(1);
assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns())
@@ -323,7 +316,6 @@ public class WebFluxConfigurationSupportTests {
@Override
public void configurePathMatching(PathMatchConfigurer configurer) {
- configurer.setUseTrailingSlashMatch(false);
configurer.addPathPrefix("/api", HandlerTypePredicate.forAnnotation(RestController.class));
}
diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java
index ae4e4a0faa..09ca3fec2e 100644
--- a/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java
+++ b/spring-webflux/src/test/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMappingTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,7 +56,6 @@ public class SimpleUrlHandlerMappingTests {
testUrl("/welcome.html", mainController, handlerMapping, "");
testUrl("/welcome.x", otherController, handlerMapping, "welcome.x");
- testUrl("/welcome/", otherController, handlerMapping, "welcome");
testUrl("/show.html", mainController, handlerMapping, "");
testUrl("/bookseats.html", mainController, handlerMapping, "");
}
diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java
index 8ccfd31895..aa2fbf1237 100644
--- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java
+++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/condition/PatternsRequestConditionTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -107,10 +107,14 @@ public class PatternsRequestConditionTests {
}
@Test
+ @SuppressWarnings("deprecation")
public void matchTrailingSlash() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
- PatternsRequestCondition condition = createPatternsCondition("/foo");
+ PathPatternParser patternParser = new PathPatternParser();
+ patternParser.setMatchOptionalTrailingSeparator(true);
+
+ PatternsRequestCondition condition = new PatternsRequestCondition(patternParser.parse("/foo"));
PatternsRequestCondition match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
@@ -118,7 +122,7 @@ public class PatternsRequestConditionTests {
.as("Should match by default")
.isEqualTo("/foo");
- condition = createPatternsCondition("/foo");
+ condition = new PatternsRequestCondition(patternParser.parse("/foo"));
match = condition.getMatchingCondition(exchange);
assertThat(match).isNotNull();
diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java
index 65481bc9ea..1862a4dd16 100644
--- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java
+++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java
@@ -119,10 +119,6 @@ public class RequestMappingInfoHandlerMappingTests {
ServerWebExchange exchange = MockServerWebExchange.from(get(""));
HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
assertThat(hm.getMethod()).isEqualTo(expected);
-
- exchange = MockServerWebExchange.from(get("/"));
- hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
- assertThat(hm.getMethod()).isEqualTo(expected);
}
@Test
@@ -157,7 +153,6 @@ public class RequestMappingInfoHandlerMappingTests {
@Test // SPR-8462
public void getHandlerMediaTypeNotSupported() {
testHttpMediaTypeNotSupportedException("/person/1");
- testHttpMediaTypeNotSupportedException("/person/1/");
testHttpMediaTypeNotSupportedException("/person/1.json");
}
@@ -175,7 +170,6 @@ public class RequestMappingInfoHandlerMappingTests {
@Test // SPR-8462
public void getHandlerTestMediaTypeNotAcceptable() {
testMediaTypeNotAcceptable("/persons");
- testMediaTypeNotAcceptable("/persons/");
}
@Test // SPR-12854
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java
index 18cf3e4813..67c96b0f8b 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java
@@ -106,8 +106,12 @@ public class PathMatchConfigurer {
/**
* Whether to match to URLs irrespective of the presence of a trailing slash.
* If enabled a method mapped to "/users" also matches to "/users/".
- * The default value is {@code true}.
+ *
The default was changed in 6.0 from {@code true} to {@code false} in
+ * order to support the deprecation of the property.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) {
this.trailingSlashMatch = trailingSlashMatch;
return this;
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java
index 7fa02e8beb..fc5dfbb208 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java
@@ -104,7 +104,10 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i
* Whether to match to URLs irrespective of the presence of a trailing slash.
* If enabled a URL pattern such as "/users" also matches to "/users/".
*
The default value is {@code false}.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch) {
this.useTrailingSlashMatch = useTrailingSlashMatch;
if (getPatternParser() != null) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
index 051ec87dbe..1da175b48b 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
@@ -140,8 +140,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
/**
* Whether to match to URLs irrespective of the presence of a trailing slash.
* If enabled a method mapped to "/users" also matches to "/users/".
- *
The default value is {@code true}.
+ *
The default was changed in 6.0 from {@code true} to {@code false} in
+ * order to support the deprecation of the property.
+ * @deprecated as of 6.0, see
+ * {@link PathPatternParser#setMatchOptionalTrailingSeparator(boolean)}
*/
+ @Deprecated
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch) {
this.useTrailingSlashMatch = useTrailingSlashMatch;
if (getPatternParser() != null) {
diff --git a/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc.xsd b/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc.xsd
index 49bac9fb9f..db09c916c7 100644
--- a/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc.xsd
+++ b/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc.xsd
@@ -52,7 +52,9 @@
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java
index 3da3bacd7c..2a335fef5a 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java
@@ -117,11 +117,6 @@ public class SimpleUrlHandlerMappingTests {
assertThat(request.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).isEqualTo("welcome.x");
assertThat(request.getAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE)).isEqualTo(otherBean);
- request = PathPatternsTestUtils.initRequest("GET", "/welcome/", usePathPatterns);
- chain = getHandler(hm, request);
- assertThat(chain.getHandler()).isSameAs(otherBean);
- assertThat(request.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)).isEqualTo("welcome");
-
request = PathPatternsTestUtils.initRequest("GET", "/", usePathPatterns);
request.setServletPath("/welcome.html");
chain = getHandler(hm, request);
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java
index 0896648285..9e299bec06 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestConditionTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -127,10 +127,14 @@ public class PathPatternsRequestConditionTests {
}
@Test
+ @SuppressWarnings("deprecation")
void matchTrailingSlash() {
MockHttpServletRequest request = createRequest("/foo/");
- PathPatternsRequestCondition condition = createCondition("/foo");
+ PathPatternParser patternParser = new PathPatternParser();
+ patternParser.setMatchOptionalTrailingSeparator(true);
+
+ PathPatternsRequestCondition condition = new PathPatternsRequestCondition(patternParser, "/foo");
PathPatternsRequestCondition match = condition.getMatchingCondition(request);
assertThat(match).isNotNull();
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
index afe58ecd52..b45eb3bbae 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-202 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -138,11 +138,6 @@ class RequestMappingInfoHandlerMappingTests {
HandlerMethod handlerMethod = getHandler(mapping, request);
assertThat(handlerMethod.getMethod()).isEqualTo(this.emptyMethod.getMethod());
-
- request = new MockHttpServletRequest("GET", "/");
- handlerMethod = getHandler(mapping, request);
-
- assertThat(handlerMethod.getMethod()).isEqualTo(this.emptyMethod.getMethod());
}
@PathPatternsParameterizedTest
@@ -174,7 +169,6 @@ class RequestMappingInfoHandlerMappingTests {
@PathPatternsParameterizedTest // SPR-8462
void getHandlerMediaTypeNotSupported(TestRequestMappingInfoHandlerMapping mapping) {
testHttpMediaTypeNotSupportedException(mapping, "/person/1");
- testHttpMediaTypeNotSupportedException(mapping, "/person/1/");
testHttpMediaTypeNotSupportedException(mapping, "/person/1.json");
}
@@ -199,7 +193,6 @@ class RequestMappingInfoHandlerMappingTests {
@PathPatternsParameterizedTest // SPR-8462
void getHandlerMediaTypeNotAccepted(TestRequestMappingInfoHandlerMapping mapping) {
testHttpMediaTypeNotAcceptableException(mapping, "/persons");
- testHttpMediaTypeNotAcceptableException(mapping, "/persons/");
if (mapping.getPatternParser() == null) {
testHttpMediaTypeNotAcceptableException(mapping, "/persons.json");
}
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java
index 091a3f4fa0..d3dc1ab219 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java
@@ -3849,7 +3849,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
@Controller
static class HttpHeadersResponseController {
- @RequestMapping(value = "", method = RequestMethod.POST)
+ @RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public HttpHeaders create() throws URISyntaxException {
HttpHeaders headers = new HttpHeaders();
diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java
index 464fad986b..89cbf094fd 100644
--- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java
+++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2020 the original author or authors.
+ * Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -225,11 +225,6 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("list");
- request = new MockHttpServletRequest("GET", "/hotels/");
- response = new MockHttpServletResponse();
- getServlet().service(request, response);
- assertThat(response.getContentAsString()).isEqualTo("list");
-
request = new MockHttpServletRequest("POST", "/hotels");
response = new MockHttpServletResponse();
getServlet().service(request, response);
@@ -240,11 +235,6 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("show-42");
- request = new MockHttpServletRequest("GET", "/hotels/42/");
- response = new MockHttpServletResponse();
- getServlet().service(request, response);
- assertThat(response.getContentAsString()).isEqualTo("show-42");
-
request = new MockHttpServletRequest("PUT", "/hotels/42");
response = new MockHttpServletResponse();
getServlet().service(request, response);
diff --git a/spring-webmvc/src/test/resources/org/springframework/web/servlet/handler/map2.xml b/spring-webmvc/src/test/resources/org/springframework/web/servlet/handler/map2.xml
index fa3ae8f0ad..1160919c66 100644
--- a/spring-webmvc/src/test/resources/org/springframework/web/servlet/handler/map2.xml
+++ b/spring-webmvc/src/test/resources/org/springframework/web/servlet/handler/map2.xml
@@ -6,7 +6,6 @@
-