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 fc20853ebe3..50d6716eb98 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -22,6 +22,7 @@ import java.util.function.Predicate; import org.springframework.lang.Nullable; import org.springframework.util.PathMatcher; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.util.UrlPathHelper; /** @@ -37,7 +38,7 @@ import org.springframework.web.util.UrlPathHelper; * * @author Brian Clozel * @since 4.0.3 - * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping + * @see RequestMappingHandlerMapping * @see org.springframework.web.servlet.handler.SimpleUrlHandlerMapping */ public class PathMatchConfigurer { @@ -46,10 +47,10 @@ public class PathMatchConfigurer { private Boolean suffixPatternMatch; @Nullable - private Boolean trailingSlashMatch; + private Boolean registeredSuffixPatternMatch; @Nullable - private Boolean registeredSuffixPatternMatch; + private Boolean trailingSlashMatch; @Nullable private UrlPathHelper urlPathHelper; @@ -66,22 +67,16 @@ public class PathMatchConfigurer { * requests. If enabled a method mapped to "/users" also matches to "/users.*". *
By default this is set to {@code true}. * @see #registeredSuffixPatternMatch + * @deprecated as of 5.2.4. See class-level note in + * {@link RequestMappingHandlerMapping} on the deprecation of path extension + * config options. */ + @Deprecated public PathMatchConfigurer setUseSuffixPatternMatch(Boolean suffixPatternMatch) { this.suffixPatternMatch = suffixPatternMatch; return this; } - /** - * 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}. - */ - public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) { - this.trailingSlashMatch = trailingSlashMatch; - return this; - } - /** * Whether suffix pattern matching should work only against path extensions * explicitly registered when you @@ -90,12 +85,26 @@ public class PathMatchConfigurer { * avoid issues such as when a "." appears in the path for other reasons. *
By default this is set to "false". * @see WebMvcConfigurer#configureContentNegotiation + * @deprecated as of 5.2.4. See class-level note in + * {@link RequestMappingHandlerMapping} on the deprecation of path extension + * config options. */ + @Deprecated public PathMatchConfigurer setUseRegisteredSuffixPatternMatch(Boolean registeredSuffixPatternMatch) { this.registeredSuffixPatternMatch = registeredSuffixPatternMatch; return this; } + /** + * 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}. + */ + public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch) { + this.trailingSlashMatch = trailingSlashMatch; + return this; + } + /** * Set the UrlPathHelper to use for resolution of lookup paths. *
Use this to override the default UrlPathHelper with a custom subclass,
@@ -137,19 +146,33 @@ public class PathMatchConfigurer {
}
+ /**
+ * Whether to use registered suffixes for pattern matching.
+ * @deprecated as of 5.2.4. See class-level note in
+ * {@link RequestMappingHandlerMapping} on the deprecation of path extension
+ * config options.
+ */
@Nullable
+ @Deprecated
public Boolean isUseSuffixPatternMatch() {
return this.suffixPatternMatch;
}
+ /**
+ * Whether to use registered suffixes for pattern matching.
+ * @deprecated as of 5.2.4. See class-level note in
+ * {@link RequestMappingHandlerMapping} on the deprecation of path extension
+ * config options.
+ */
@Nullable
- public Boolean isUseTrailingSlashMatch() {
- return this.trailingSlashMatch;
+ @Deprecated
+ public Boolean isUseRegisteredSuffixPatternMatch() {
+ return this.registeredSuffixPatternMatch;
}
@Nullable
- public Boolean isUseRegisteredSuffixPatternMatch() {
- return this.registeredSuffixPatternMatch;
+ public Boolean isUseTrailingSlashMatch() {
+ return this.trailingSlashMatch;
}
@Nullable
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
index d8f93bf4e54..1000fe12b7d 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2020 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.
@@ -275,6 +275,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
* requests to annotated controllers.
*/
@Bean
+ @SuppressWarnings("deprecation")
public RequestMappingHandlerMapping requestMappingHandlerMapping(
@Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager,
@Qualifier("mvcConversionService") FormattingConversionService conversionService,
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java
index 1c1fd482c5f..f5df9068803 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2020 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.
@@ -33,6 +33,7 @@ import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerMapping;
+import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.util.UrlPathHelper;
/**
@@ -58,23 +59,42 @@ public final class PatternsRequestCondition extends AbstractRequestCondition Note: In 5.3, {@link #setUseRegisteredSuffixPatternMatch(boolean) useRegisteredSuffixPatternMatch}
+ * switches to being on by default so that path matching becomes constrained
+ * to registered suffixes only.
+ *
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @author Sam Brannen
@@ -89,7 +101,10 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
* The default value is {@code true}.
* Also see {@link #setUseRegisteredSuffixPatternMatch(boolean)} for
* more fine-grained control over specific suffixes to allow.
+ * @deprecated as of 5.2.4. See class level comment about deprecation of
+ * path extension config options.
*/
+ @Deprecated
public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch) {
this.useSuffixPatternMatch = useSuffixPatternMatch;
}
@@ -100,7 +115,11 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
* is generally recommended to reduce ambiguity and to avoid issues such as
* when a "." appears in the path for other reasons.
* By default this is set to "false".
+ * @deprecated as of 5.2.4. See class level comment about deprecation of
+ * path extension config options note also that in 5.3 the default for this
+ * property will switch from {@code false} to {@code true}.
*/
+ @Deprecated
public void setUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch) {
this.useRegisteredSuffixPatternMatch = useRegisteredSuffixPatternMatch;
this.useSuffixPatternMatch = (useRegisteredSuffixPatternMatch || this.useSuffixPatternMatch);
@@ -159,13 +178,14 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
}
@Override
+ @SuppressWarnings("deprecation")
public void afterPropertiesSet() {
this.config = new RequestMappingInfo.BuilderConfiguration();
this.config.setUrlPathHelper(getUrlPathHelper());
this.config.setPathMatcher(getPathMatcher());
- this.config.setSuffixPatternMatch(this.useSuffixPatternMatch);
- this.config.setTrailingSlashMatch(this.useTrailingSlashMatch);
- this.config.setRegisteredSuffixPatternMatch(this.useRegisteredSuffixPatternMatch);
+ this.config.setSuffixPatternMatch(useSuffixPatternMatch());
+ this.config.setTrailingSlashMatch(useTrailingSlashMatch());
+ this.config.setRegisteredSuffixPatternMatch(useRegisteredSuffixPatternMatch());
this.config.setContentNegotiationManager(getContentNegotiationManager());
super.afterPropertiesSet();
@@ -173,15 +193,21 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
/**
- * Whether to use suffix pattern matching.
+ * Whether to use registered suffixes for pattern matching.
+ * @deprecated as of 5.2.4. See class-level note on the deprecation of path
+ * extension config options.
*/
+ @Deprecated
public boolean useSuffixPatternMatch() {
return this.useSuffixPatternMatch;
}
/**
* Whether to use registered suffixes for pattern matching.
+ * @deprecated as of 5.2.4. See class-level note on the deprecation of path
+ * extension config options.
*/
+ @Deprecated
public boolean useRegisteredSuffixPatternMatch() {
return this.useRegisteredSuffixPatternMatch;
}
@@ -195,8 +221,12 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
/**
* Return the file extensions to use for suffix pattern matching.
+ * @deprecated as of 5.2.4. See class-level note on the deprecation of path
+ * extension config options.
*/
@Nullable
+ @Deprecated
+ @SuppressWarnings("deprecation")
public List