Commit 1e648801 authored by Brian Clozel's avatar Brian Clozel

Move spring.mvc.media-types to content-negotiation

This commit moves "spring.mvc.media-types" to the
"spring.mvc.content-negotiation.*" namespaces introduced in gh-11105.

Closes gh-11636
parent 76057be9
...@@ -232,7 +232,7 @@ public class WebMvcAutoConfiguration { ...@@ -232,7 +232,7 @@ public class WebMvcAutoConfiguration {
if (contentNegotiation.getParameterName() != null) { if (contentNegotiation.getParameterName() != null) {
configurer.parameterName(contentNegotiation.getParameterName()); configurer.parameterName(contentNegotiation.getParameterName());
} }
Map<String, MediaType> mediaTypes = this.mvcProperties.getMediaTypes(); Map<String, MediaType> mediaTypes = this.mvcProperties.getContentNegotiation().getMediaTypes();
for (Entry<String, MediaType> mediaType : mediaTypes.entrySet()) { for (Entry<String, MediaType> mediaType : mediaTypes.entrySet()) {
configurer.mediaType(mediaType.getKey(), mediaType.getValue()); configurer.mediaType(mediaType.getKey(), mediaType.getValue());
} }
......
...@@ -87,11 +87,6 @@ public class WebMvcProperties { ...@@ -87,11 +87,6 @@ public class WebMvcProperties {
*/ */
private boolean logResolvedException = false; private boolean logResolvedException = false;
/**
* Maps file extensions to media types for content negotiation, e.g. yml to text/yaml.
*/
private Map<String, MediaType> mediaTypes = new LinkedHashMap<>();
/** /**
* Path pattern used for static resources. * Path pattern used for static resources.
*/ */
...@@ -165,14 +160,6 @@ public class WebMvcProperties { ...@@ -165,14 +160,6 @@ public class WebMvcProperties {
this.logResolvedException = logResolvedException; this.logResolvedException = logResolvedException;
} }
public Map<String, MediaType> getMediaTypes() {
return this.mediaTypes;
}
public void setMediaTypes(Map<String, MediaType> mediaTypes) {
this.mediaTypes = mediaTypes;
}
public boolean isDispatchOptionsRequest() { public boolean isDispatchOptionsRequest() {
return this.dispatchOptionsRequest; return this.dispatchOptionsRequest;
} }
...@@ -298,6 +285,11 @@ public class WebMvcProperties { ...@@ -298,6 +285,11 @@ public class WebMvcProperties {
*/ */
private boolean favorParameter = false; private boolean favorParameter = false;
/**
* Maps file extensions to media types for content negotiation, e.g. yml to text/yaml.
*/
private Map<String, MediaType> mediaTypes = new LinkedHashMap<>();
/** /**
* Query parameter name to use when "favor-parameter" is enabled. * Query parameter name to use when "favor-parameter" is enabled.
*/ */
...@@ -319,6 +311,14 @@ public class WebMvcProperties { ...@@ -319,6 +311,14 @@ public class WebMvcProperties {
this.favorParameter = favorParameter; this.favorParameter = favorParameter;
} }
public Map<String, MediaType> getMediaTypes() {
return this.mediaTypes;
}
public void setMediaTypes(Map<String, MediaType> mediaTypes) {
this.mediaTypes = mediaTypes;
}
public String getParameterName() { public String getParameterName() {
return this.parameterName; return this.parameterName;
} }
...@@ -337,8 +337,8 @@ public class WebMvcProperties { ...@@ -337,8 +337,8 @@ public class WebMvcProperties {
private boolean useSuffixPattern = false; private boolean useSuffixPattern = false;
/** /**
* Whether suffix pattern matching should work only against path extensions * Whether suffix pattern matching should work only against extensions
* explicitly registered with "spring.mvc.media-types.*". * registered with "spring.mvc.content-negotiation.media-types.*".
* This is generally recommended to reduce ambiguity and to * This is generally recommended to reduce ambiguity and to
* avoid issues such as when a "." appears in the path for other reasons. * avoid issues such as when a "." appears in the path for other reasons.
*/ */
......
...@@ -409,6 +409,15 @@ ...@@ -409,6 +409,15 @@
"description": "Whether to enable Spring's HttpPutFormContentFilter.", "description": "Whether to enable Spring's HttpPutFormContentFilter.",
"defaultValue": true "defaultValue": true
}, },
{
"name" : "spring.mvc.media-types",
"type" : "java.util.Map<java.lang.String,org.springframework.http.MediaType>",
"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", "name": "spring.mvc.locale-resolver",
"defaultValue": "accept-header" "defaultValue": "accept-header"
......
...@@ -471,7 +471,8 @@ public class WebMvcAutoConfigurationTests { ...@@ -471,7 +471,8 @@ public class WebMvcAutoConfigurationTests {
@Test @Test
public void customMediaTypes() { 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") "spring.mvc.content-negotiation.favor-path-extension:true")
.run((context) -> { .run((context) -> {
RequestMappingHandlerAdapter adapter = context RequestMappingHandlerAdapter adapter = context
......
...@@ -395,6 +395,7 @@ content into your application. Rather, pick only the properties that you need. ...@@ -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.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-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.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.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.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. 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. ...@@ -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= # 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.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.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.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.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.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. spring.mvc.static-path-pattern=/** # Path pattern used for static resources.
......
...@@ -2082,7 +2082,7 @@ will be mapped to `@GetMapping("/project/spring-boot")`: ...@@ -2082,7 +2082,7 @@ will be mapped to `@GetMapping("/project/spring-boot")`:
# spring.mvc.content-negotiation.parameter-name=myparam # spring.mvc.content-negotiation.parameter-name=myparam
# We can also register additional file extensions/media types with: # 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 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: ...@@ -2096,7 +2096,7 @@ suffix pattern matching, the following configuration is required:
# spring.mvc.path-match.use-registered-suffix-pattern=true # spring.mvc.path-match.use-registered-suffix-pattern=true
# We can also register additional file extensions/media types with: # 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
---- ----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment