diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index f49cff6395..91c3193934 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.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. @@ -81,15 +81,18 @@ import org.springframework.web.context.ServletContextAware; * * * - *
As of 5.0 you can set the exact strategies to use via + *
Alternatively you can avoid use of the above convenience builder + * methods and set the exact strategies to use via * {@link #setStrategies(List)}. * - *
Note: if you must use URL-based content type resolution, - * the use of a query parameter is simpler and preferable to the use of a path - * extension since the latter can cause issues with URI variables, path - * parameters, and URI decoding. Consider setting {@link #setFavorPathExtension} - * to {@literal false} or otherwise set the strategies to use explicitly via - * {@link #setStrategies(List)}. + *
Note: As of 5.2.4, + * {@link #setFavorPathExtension(boolean) favorPathExtension} and + * {@link #setIgnoreUnknownPathExtensions(boolean) ignoreUnknownPathExtensions} + * are deprecated in order to discourage use of path extensions for content + * negotiation and for request mapping (with similar deprecations in + * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping + * RequestMappingHandlerMapping}). For further context, please read issue + * #24719. * * @author Rossen Stoyanchev * @author Brian Clozel @@ -145,7 +148,10 @@ public class ContentNegotiationManagerFactoryBean *
By default this is set to {@code true} in which case a request * for {@code /hotels.pdf} will be interpreted as a request for * {@code "application/pdf"} regardless of the 'Accept' header. + * @deprecated as of 5.2.4. See class-level note on the deprecation of path + * extension config options. */ + @Deprecated public void setFavorPathExtension(boolean favorPathExtension) { this.favorPathExtension = favorPathExtension; } @@ -199,7 +205,10 @@ public class ContentNegotiationManagerFactoryBean * to any media type. Setting this to {@code false} will result in an * {@code HttpMediaTypeNotAcceptableException} if there is no match. *
By default this is set to {@code true}. + * @deprecated as of 5.2.4. See class-level note on the deprecation of path + * extension config options. */ + @Deprecated public void setIgnoreUnknownPathExtensions(boolean ignore) { this.ignoreUnknownPathExtensions = ignore; } @@ -303,7 +312,7 @@ public class ContentNegotiationManagerFactoryBean } /** - * Actually build the {@link ContentNegotiationManager}. + * Create and initialize a {@link ContentNegotiationManager} instance. * @since 5.0 */ public ContentNegotiationManager build() { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java index 6b0c2522ea..b1ce073255 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.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. @@ -32,7 +32,6 @@ import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.accept.FixedContentNegotiationStrategy; import org.springframework.web.accept.HeaderContentNegotiationStrategy; import org.springframework.web.accept.ParameterContentNegotiationStrategy; -import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; /** * Creates a {@code ContentNegotiationManager} and configures it with @@ -52,7 +51,8 @@ import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; *
By default this is set to {@code true} in which case a request * for {@code /hotels.pdf} will be interpreted as a request for * {@code "application/pdf"} regardless of the 'Accept' header. + * @deprecated as of 5.2.4. See class-level note in + * {@link ContentNegotiationManagerFactoryBean} on the deprecation of path + * extension config options. */ + @Deprecated public ContentNegotiationConfigurer favorPathExtension(boolean favorPathExtension) { this.factory.setFavorPathExtension(favorPathExtension); return this; @@ -183,7 +187,11 @@ public class ContentNegotiationConfigurer { * to any media type. Setting this to {@code false} will result in an * {@code HttpMediaTypeNotAcceptableException} if there is no match. *
By default this is set to {@code true}. + * @deprecated as of 5.2.4. See class-level note in + * {@link ContentNegotiationManagerFactoryBean} on the deprecation of path + * extension config options. */ + @Deprecated public ContentNegotiationConfigurer ignoreUnknownPathExtensions(boolean ignore) { this.factory.setIgnoreUnknownPathExtensions(ignore); return this;