From ab01c55d8e6dcbc8d7e7020f9200bc0ec1963f53 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 26 Mar 2020 10:28:24 +0100 Subject: [PATCH] Deprecate use of path extensions for request mapping and content negotiation Closes gh-20528 --- .../web/servlet/WebMvcAutoConfiguration.java | 4 +++- .../web/servlet/WebMvcProperties.java | 15 ++++++++++++++- .../web/servlet/WebMvcAutoConfigurationTests.java | 6 +++++- .../src/main/asciidoc/spring-boot-features.adoc | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index ca31a0c36a..fc103d5530 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -220,6 +220,7 @@ public class WebMvcAutoConfiguration { } @Override + @SuppressWarnings("deprecation") public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseSuffixPatternMatch(this.mvcProperties.getPathmatch().isUseSuffixPattern()); configurer.setUseRegisteredSuffixPatternMatch( @@ -227,6 +228,7 @@ public class WebMvcAutoConfiguration { } @Override + @SuppressWarnings("deprecation") public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { WebMvcProperties.Contentnegotiation contentnegotiation = this.mvcProperties.getContentnegotiation(); configurer.favorPathExtension(contentnegotiation.isFavorPathExtension()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java index 60ea3c919e..5a9556de95 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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.Locale; import java.util.Map; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.validation.DefaultMessageCodesResolver; @@ -352,10 +353,14 @@ public class WebMvcProperties { */ private String parameterName; + @DeprecatedConfigurationProperty( + reason = "Use of path extensions for request mapping and for content negotiation is discouraged.") + @Deprecated public boolean isFavorPathExtension() { return this.favorPathExtension; } + @Deprecated public void setFavorPathExtension(boolean favorPathExtension) { this.favorPathExtension = favorPathExtension; } @@ -402,18 +407,26 @@ public class WebMvcProperties { */ private boolean useRegisteredSuffixPattern = false; + @DeprecatedConfigurationProperty( + reason = "Use of path extensions for request mapping and for content negotiation is discouraged.") + @Deprecated public boolean isUseSuffixPattern() { return this.useSuffixPattern; } + @Deprecated public void setUseSuffixPattern(boolean useSuffixPattern) { this.useSuffixPattern = useSuffixPattern; } + @DeprecatedConfigurationProperty( + reason = "Use of path extensions for request mapping and for content negotiation is discouraged.") + @Deprecated public boolean isUseRegisteredSuffixPattern() { return this.useRegisteredSuffixPattern; } + @Deprecated public void setUseRegisteredSuffixPattern(boolean useRegisteredSuffixPattern) { this.useRegisteredSuffixPattern = useRegisteredSuffixPattern; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 16d63d8e0e..23c58e64f0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -432,6 +432,7 @@ class WebMvcAutoConfigurationTests { } @Test + @Deprecated void customMediaTypes() { this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.media-types.yaml:text/yaml", "spring.mvc.contentnegotiation.favor-path-extension:true").run((context) -> { @@ -687,6 +688,7 @@ class WebMvcAutoConfigurationTests { } @Test + @Deprecated void useSuffixPatternMatch() { this.contextRunner.withPropertyValues("spring.mvc.pathmatch.use-suffix-pattern:true", "spring.mvc.pathmatch.use-registered-suffix-pattern:true").run((context) -> { @@ -707,6 +709,7 @@ class WebMvcAutoConfigurationTests { } @Test + @Deprecated void pathExtensionContentNegotiation() { this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.favor-path-extension:true") .run((context) -> { @@ -718,6 +721,7 @@ class WebMvcAutoConfigurationTests { } @Test + @Deprecated void queryParameterContentNegotiation() { this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.favor-parameter:true").run((context) -> { RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class); diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 9eeb1e25b7..ff311f558c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2211,6 +2211,7 @@ Instead of using suffix matching, we can use a query parameter to ensure that re spring.mvc.contentnegotiation.media-types.markdown=text/markdown ---- +Suffix pattern matching is deprecated and will be removed in a future release. If you understand the caveats and would still like your application to use suffix pattern matching, the following configuration is required: [source,properties,indent=0,subs="verbatim,quotes,attributes",configprops]