Skip to content

Commit ab01c55

Browse files
committed
Deprecate use of path extensions for request mapping and content negotiation
Closes gh-20528
1 parent 0c3be4d commit ab01c55

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -220,13 +220,15 @@ public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
220220
}
221221

222222
@Override
223+
@SuppressWarnings("deprecation")
223224
public void configurePathMatch(PathMatchConfigurer configurer) {
224225
configurer.setUseSuffixPatternMatch(this.mvcProperties.getPathmatch().isUseSuffixPattern());
225226
configurer.setUseRegisteredSuffixPatternMatch(
226227
this.mvcProperties.getPathmatch().isUseRegisteredSuffixPattern());
227228
}
228229

229230
@Override
231+
@SuppressWarnings("deprecation")
230232
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
231233
WebMvcProperties.Contentnegotiation contentnegotiation = this.mvcProperties.getContentnegotiation();
232234
configurer.favorPathExtension(contentnegotiation.isFavorPathExtension());

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -22,6 +22,7 @@
2222
import java.util.Map;
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
2526
import org.springframework.http.MediaType;
2627
import org.springframework.util.Assert;
2728
import org.springframework.validation.DefaultMessageCodesResolver;
@@ -352,10 +353,14 @@ public static class Contentnegotiation {
352353
*/
353354
private String parameterName;
354355

356+
@DeprecatedConfigurationProperty(
357+
reason = "Use of path extensions for request mapping and for content negotiation is discouraged.")
358+
@Deprecated
355359
public boolean isFavorPathExtension() {
356360
return this.favorPathExtension;
357361
}
358362

363+
@Deprecated
359364
public void setFavorPathExtension(boolean favorPathExtension) {
360365
this.favorPathExtension = favorPathExtension;
361366
}
@@ -402,18 +407,26 @@ public static class Pathmatch {
402407
*/
403408
private boolean useRegisteredSuffixPattern = false;
404409

410+
@DeprecatedConfigurationProperty(
411+
reason = "Use of path extensions for request mapping and for content negotiation is discouraged.")
412+
@Deprecated
405413
public boolean isUseSuffixPattern() {
406414
return this.useSuffixPattern;
407415
}
408416

417+
@Deprecated
409418
public void setUseSuffixPattern(boolean useSuffixPattern) {
410419
this.useSuffixPattern = useSuffixPattern;
411420
}
412421

422+
@DeprecatedConfigurationProperty(
423+
reason = "Use of path extensions for request mapping and for content negotiation is discouraged.")
424+
@Deprecated
413425
public boolean isUseRegisteredSuffixPattern() {
414426
return this.useRegisteredSuffixPattern;
415427
}
416428

429+
@Deprecated
417430
public void setUseRegisteredSuffixPattern(boolean useRegisteredSuffixPattern) {
418431
this.useRegisteredSuffixPattern = useRegisteredSuffixPattern;
419432
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -432,6 +432,7 @@ void asyncTaskExecutorWithCustomNonApplicationTaskExecutor() {
432432
}
433433

434434
@Test
435+
@Deprecated
435436
void customMediaTypes() {
436437
this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.media-types.yaml:text/yaml",
437438
"spring.mvc.contentnegotiation.favor-path-extension:true").run((context) -> {
@@ -687,6 +688,7 @@ void defaultPathMatching() {
687688
}
688689

689690
@Test
691+
@Deprecated
690692
void useSuffixPatternMatch() {
691693
this.contextRunner.withPropertyValues("spring.mvc.pathmatch.use-suffix-pattern:true",
692694
"spring.mvc.pathmatch.use-registered-suffix-pattern:true").run((context) -> {
@@ -707,6 +709,7 @@ void defaultContentNegotiation() {
707709
}
708710

709711
@Test
712+
@Deprecated
710713
void pathExtensionContentNegotiation() {
711714
this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.favor-path-extension:true")
712715
.run((context) -> {
@@ -718,6 +721,7 @@ void pathExtensionContentNegotiation() {
718721
}
719722

720723
@Test
724+
@Deprecated
721725
void queryParameterContentNegotiation() {
722726
this.contextRunner.withPropertyValues("spring.mvc.contentnegotiation.favor-parameter:true").run((context) -> {
723727
RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class);

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,7 @@ Instead of using suffix matching, we can use a query parameter to ensure that re
22112211
spring.mvc.contentnegotiation.media-types.markdown=text/markdown
22122212
----
22132213

2214+
Suffix pattern matching is deprecated and will be removed in a future release.
22142215
If you understand the caveats and would still like your application to use suffix pattern matching, the following configuration is required:
22152216

22162217
[source,properties,indent=0,subs="verbatim,quotes,attributes",configprops]

0 commit comments

Comments
 (0)