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 50d22f8c45..4c2b70ac62 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 @@ -232,7 +232,7 @@ public class WebMvcAutoConfiguration { if (contentNegotiation.getParameterName() != null) { configurer.parameterName(contentNegotiation.getParameterName()); } - Map mediaTypes = this.mvcProperties.getMediaTypes(); + Map mediaTypes = this.mvcProperties.getContentNegotiation().getMediaTypes(); for (Entry mediaType : mediaTypes.entrySet()) { configurer.mediaType(mediaType.getKey(), mediaType.getValue()); } 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 f9c2d88ea7..c881359fcc 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 @@ -87,11 +87,6 @@ public class WebMvcProperties { */ private boolean logResolvedException = false; - /** - * Maps file extensions to media types for content negotiation, e.g. yml to text/yaml. - */ - private Map mediaTypes = new LinkedHashMap<>(); - /** * Path pattern used for static resources. */ @@ -165,14 +160,6 @@ public class WebMvcProperties { this.logResolvedException = logResolvedException; } - public Map getMediaTypes() { - return this.mediaTypes; - } - - public void setMediaTypes(Map mediaTypes) { - this.mediaTypes = mediaTypes; - } - public boolean isDispatchOptionsRequest() { return this.dispatchOptionsRequest; } @@ -298,6 +285,11 @@ public class WebMvcProperties { */ private boolean favorParameter = false; + /** + * Maps file extensions to media types for content negotiation, e.g. yml to text/yaml. + */ + private Map mediaTypes = new LinkedHashMap<>(); + /** * Query parameter name to use when "favor-parameter" is enabled. */ @@ -319,6 +311,14 @@ public class WebMvcProperties { this.favorParameter = favorParameter; } + public Map getMediaTypes() { + return this.mediaTypes; + } + + public void setMediaTypes(Map mediaTypes) { + this.mediaTypes = mediaTypes; + } + public String getParameterName() { return this.parameterName; } @@ -337,8 +337,8 @@ public class WebMvcProperties { private boolean useSuffixPattern = false; /** - * Whether suffix pattern matching should work only against path extensions - * explicitly registered with "spring.mvc.media-types.*". + * Whether suffix pattern matching should work only against extensions + * registered with "spring.mvc.content-negotiation.media-types.*". * This is generally recommended to reduce ambiguity and to * avoid issues such as when a "." appears in the path for other reasons. */ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index f67b215b45..e742c1376c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -409,6 +409,15 @@ "description": "Whether to enable Spring's HttpPutFormContentFilter.", "defaultValue": true }, + { + "name" : "spring.mvc.media-types", + "type" : "java.util.Map", + "description" : "Maps file extensions to media types for content negotiation, e.g. yml to text/yaml.", + "deprecation" : { + "replacement" : "spring.mvc.content-negotiation.media-types", + "level" : "error" + } + }, { "name": "spring.mvc.locale-resolver", "defaultValue": "accept-header" 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 06c72a7af2..43dcba62e1 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 @@ -471,7 +471,8 @@ public class WebMvcAutoConfigurationTests { @Test public void customMediaTypes() { - this.contextRunner.withPropertyValues("spring.mvc.mediaTypes.yaml:text/yaml", + this.contextRunner.withPropertyValues( + "spring.mvc.content-negotiation.media-types.yaml:text/yaml", "spring.mvc.content-negotiation.favor-path-extension:true") .run((context) -> { RequestMappingHandlerAdapter adapter = context diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 6af4c2372b..a5fc55cb3b 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -395,6 +395,7 @@ content into your application. Rather, pick only the properties that you need. spring.mvc.async.request-timeout= # Amount of time before asynchronous request handling times out. spring.mvc.content-negotiation.favor-path-extension=false # Whether the path extension in the URL path should be used to determine the requested media type. spring.mvc.content-negotiation.favor-parameter=false # Whether a request parameter ("format" by default) should be used to determine the requested media type. + spring.mvc.content-negotiation.media-types.*= # Maps file extensions to media types for content negotiation. spring.mvc.content-negotiation.parameter-name= # Query parameter name to use when "favor-parameter" is enabled. spring.mvc.date-format= # Date format to use. For instance, `dd/MM/yyyy`. spring.mvc.dispatch-trace-request=false # Whether to dispatch TRACE requests to the FrameworkServlet doService method. @@ -405,9 +406,8 @@ content into your application. Rather, pick only the properties that you need. spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header. spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved. spring.mvc.log-resolved-exception=false # Whether to enable warn logging of exceptions resolved by a "HandlerExceptionResolver". - spring.mvc.media-types.*= # Maps file extensions to media types for content negotiation. spring.mvc.message-codes-resolver-format= # Formatting strategy for message codes. For instance, `PREFIX_ERROR_CODE`. - spring.mvc.path-match.use-registered-suffix-pattern=false # Whether suffix pattern matching should work only against path extensions explicitly registered with "spring.mvc.media-types.*". + spring.mvc.path-match.use-registered-suffix-pattern=false # Whether suffix pattern matching should work only against extensions registered with "spring.mvc.content-negotiation.media-types.*". spring.mvc.path-match.use-suffix-pattern=false # Whether to use suffix pattern match (".*") when matching patterns to requests. spring.mvc.servlet.load-on-startup=-1 # Load on startup priority of the Spring Web Services servlet. spring.mvc.static-path-pattern=/** # Path pattern used for static resources. 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 a9964f145e..292c7fdd1b 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 @@ -2082,7 +2082,7 @@ will be mapped to `@GetMapping("/project/spring-boot")`: # spring.mvc.content-negotiation.parameter-name=myparam # We can also register additional file extensions/media types with: - spring.mvc.media-types.markdown=text/markdown + spring.mvc.content-negotiation.media-types.markdown=text/markdown ---- If you understand the caveats and would still like your application to use @@ -2096,7 +2096,7 @@ suffix pattern matching, the following configuration is required: # spring.mvc.path-match.use-registered-suffix-pattern=true # We can also register additional file extensions/media types with: - # spring.mvc.media-types.adoc=text/asciidoc + # spring.mvc.content-negotiation.media-types.adoc=text/asciidoc ----