Skip to content

Commit 1e64880

Browse files
committed
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
1 parent 76057be commit 1e64880

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
232232
if (contentNegotiation.getParameterName() != null) {
233233
configurer.parameterName(contentNegotiation.getParameterName());
234234
}
235-
Map<String, MediaType> mediaTypes = this.mvcProperties.getMediaTypes();
235+
Map<String, MediaType> mediaTypes = this.mvcProperties.getContentNegotiation().getMediaTypes();
236236
for (Entry<String, MediaType> mediaType : mediaTypes.entrySet()) {
237237
configurer.mediaType(mediaType.getKey(), mediaType.getValue());
238238
}

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ public class WebMvcProperties {
8787
*/
8888
private boolean logResolvedException = false;
8989

90-
/**
91-
* Maps file extensions to media types for content negotiation, e.g. yml to text/yaml.
92-
*/
93-
private Map<String, MediaType> mediaTypes = new LinkedHashMap<>();
94-
9590
/**
9691
* Path pattern used for static resources.
9792
*/
@@ -165,14 +160,6 @@ public void setLogResolvedException(boolean logResolvedException) {
165160
this.logResolvedException = logResolvedException;
166161
}
167162

168-
public Map<String, MediaType> getMediaTypes() {
169-
return this.mediaTypes;
170-
}
171-
172-
public void setMediaTypes(Map<String, MediaType> mediaTypes) {
173-
this.mediaTypes = mediaTypes;
174-
}
175-
176163
public boolean isDispatchOptionsRequest() {
177164
return this.dispatchOptionsRequest;
178165
}
@@ -298,6 +285,11 @@ public static class ContentNegotiation {
298285
*/
299286
private boolean favorParameter = false;
300287

288+
/**
289+
* Maps file extensions to media types for content negotiation, e.g. yml to text/yaml.
290+
*/
291+
private Map<String, MediaType> mediaTypes = new LinkedHashMap<>();
292+
301293
/**
302294
* Query parameter name to use when "favor-parameter" is enabled.
303295
*/
@@ -319,6 +311,14 @@ public void setFavorParameter(boolean favorParameter) {
319311
this.favorParameter = favorParameter;
320312
}
321313

314+
public Map<String, MediaType> getMediaTypes() {
315+
return this.mediaTypes;
316+
}
317+
318+
public void setMediaTypes(Map<String, MediaType> mediaTypes) {
319+
this.mediaTypes = mediaTypes;
320+
}
321+
322322
public String getParameterName() {
323323
return this.parameterName;
324324
}
@@ -337,8 +337,8 @@ public static class PathMatch {
337337
private boolean useSuffixPattern = false;
338338

339339
/**
340-
* Whether suffix pattern matching should work only against path extensions
341-
* explicitly registered with "spring.mvc.media-types.*".
340+
* Whether suffix pattern matching should work only against extensions
341+
* registered with "spring.mvc.content-negotiation.media-types.*".
342342
* This is generally recommended to reduce ambiguity and to
343343
* avoid issues such as when a "." appears in the path for other reasons.
344344
*/

spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+9
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,15 @@
409409
"description": "Whether to enable Spring's HttpPutFormContentFilter.",
410410
"defaultValue": true
411411
},
412+
{
413+
"name" : "spring.mvc.media-types",
414+
"type" : "java.util.Map<java.lang.String,org.springframework.http.MediaType>",
415+
"description" : "Maps file extensions to media types for content negotiation, e.g. yml to text/yaml.",
416+
"deprecation" : {
417+
"replacement" : "spring.mvc.content-negotiation.media-types",
418+
"level" : "error"
419+
}
420+
},
412421
{
413422
"name": "spring.mvc.locale-resolver",
414423
"defaultValue": "accept-header"

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ public void customAsyncRequestTimeout() {
471471

472472
@Test
473473
public void customMediaTypes() {
474-
this.contextRunner.withPropertyValues("spring.mvc.mediaTypes.yaml:text/yaml",
474+
this.contextRunner.withPropertyValues(
475+
"spring.mvc.content-negotiation.media-types.yaml:text/yaml",
475476
"spring.mvc.content-negotiation.favor-path-extension:true")
476477
.run((context) -> {
477478
RequestMappingHandlerAdapter adapter = context

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ content into your application. Rather, pick only the properties that you need.
395395
spring.mvc.async.request-timeout= # Amount of time before asynchronous request handling times out.
396396
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.
397397
spring.mvc.content-negotiation.favor-parameter=false # Whether a request parameter ("format" by default) should be used to determine the requested media type.
398+
spring.mvc.content-negotiation.media-types.*= # Maps file extensions to media types for content negotiation.
398399
spring.mvc.content-negotiation.parameter-name= # Query parameter name to use when "favor-parameter" is enabled.
399400
spring.mvc.date-format= # Date format to use. For instance, `dd/MM/yyyy`.
400401
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.
405406
spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header.
406407
spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved.
407408
spring.mvc.log-resolved-exception=false # Whether to enable warn logging of exceptions resolved by a "HandlerExceptionResolver".
408-
spring.mvc.media-types.*= # Maps file extensions to media types for content negotiation.
409409
spring.mvc.message-codes-resolver-format= # Formatting strategy for message codes. For instance, `PREFIX_ERROR_CODE`.
410-
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.*".
410+
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.*".
411411
spring.mvc.path-match.use-suffix-pattern=false # Whether to use suffix pattern match (".*") when matching patterns to requests.
412412
spring.mvc.servlet.load-on-startup=-1 # Load on startup priority of the Spring Web Services servlet.
413413
spring.mvc.static-path-pattern=/** # Path pattern used for static resources.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ will be mapped to `@GetMapping("/project/spring-boot")`:
20822082
# spring.mvc.content-negotiation.parameter-name=myparam
20832083
20842084
# We can also register additional file extensions/media types with:
2085-
spring.mvc.media-types.markdown=text/markdown
2085+
spring.mvc.content-negotiation.media-types.markdown=text/markdown
20862086
----
20872087

20882088
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:
20962096
# spring.mvc.path-match.use-registered-suffix-pattern=true
20972097
20982098
# We can also register additional file extensions/media types with:
2099-
# spring.mvc.media-types.adoc=text/asciidoc
2099+
# spring.mvc.content-negotiation.media-types.adoc=text/asciidoc
21002100
----
21012101

21022102

0 commit comments

Comments
 (0)