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
This commit is contained in:
@@ -232,7 +232,7 @@ public class WebMvcAutoConfiguration {
|
||||
if (contentNegotiation.getParameterName() != null) {
|
||||
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()) {
|
||||
configurer.mediaType(mediaType.getKey(), mediaType.getValue());
|
||||
}
|
||||
|
||||
@@ -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<String, MediaType> mediaTypes = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Path pattern used for static resources.
|
||||
*/
|
||||
@@ -165,14 +160,6 @@ public class WebMvcProperties {
|
||||
this.logResolvedException = logResolvedException;
|
||||
}
|
||||
|
||||
public Map<String, MediaType> getMediaTypes() {
|
||||
return this.mediaTypes;
|
||||
}
|
||||
|
||||
public void setMediaTypes(Map<String, MediaType> 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<String, MediaType> 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<String, MediaType> getMediaTypes() {
|
||||
return this.mediaTypes;
|
||||
}
|
||||
|
||||
public void setMediaTypes(Map<String, MediaType> 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.
|
||||
*/
|
||||
|
||||
@@ -409,6 +409,15 @@
|
||||
"description": "Whether to enable Spring's HttpPutFormContentFilter.",
|
||||
"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",
|
||||
"defaultValue": "accept-header"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
----
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user