Skip to content

Commit 4a47c1e

Browse files
committed
Keep default Thymeleaf media types in reactive support
This commit removes the default configuration value previously set for `spring.thymeleaf.reactive.media-types` since this value overrides the defaults provided by Thymeleaf. This value does not drive the default media type used by views, but rather all media types that the templating engine should support. Fixes gh-9134
1 parent 89c284c commit 4a47c1e

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121
import java.util.LinkedHashMap;
22+
import java.util.List;
2223

2324
import javax.annotation.PostConstruct;
2425

@@ -55,6 +56,7 @@
5556
import org.springframework.context.annotation.Bean;
5657
import org.springframework.context.annotation.Configuration;
5758
import org.springframework.core.Ordered;
59+
import org.springframework.http.MediaType;
5860
import org.springframework.util.MimeType;
5961
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
6062

@@ -252,8 +254,10 @@ public ThymeleafReactiveViewResolver thymeleafViewResolver(
252254
ThymeleafReactiveViewResolver resolver = new ThymeleafReactiveViewResolver();
253255
resolver.setTemplateEngine(templateEngine);
254256
resolver.setDefaultCharset(this.properties.getEncoding());
255-
resolver.setSupportedMediaTypes(
256-
this.properties.getReactive().getMediaTypes());
257+
final List<MediaType> mediaTypes = this.properties.getReactive().getMediaTypes();
258+
if (mediaTypes != null) {
259+
resolver.setSupportedMediaTypes(mediaTypes);
260+
}
257261
resolver.setExcludedViewNames(this.properties.getExcludedViewNames());
258262
resolver.setViewNames(this.properties.getViewNames());
259263
if (this.properties.getReactive().getMaxChunkSize() > 0) {

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package org.springframework.boot.autoconfigure.thymeleaf;
1818

1919
import java.nio.charset.Charset;
20-
import java.util.ArrayList;
21-
import java.util.Collections;
2220
import java.util.List;
2321

2422
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -227,8 +225,7 @@ public static class Reactive {
227225
/**
228226
* Media types supported by the view technology.
229227
*/
230-
private List<MediaType> mediaTypes = new ArrayList<>(
231-
Collections.singletonList(MediaType.TEXT_HTML));
228+
private List<MediaType> mediaTypes;
232229

233230
public List<MediaType> getMediaTypes() {
234231
return this.mediaTypes;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ content into your application; rather pick only the properties that you need.
441441
spring.thymeleaf.mode=HTML5 # Template mode to be applied to templates. See also StandardTemplateModeHandlers.
442442
spring.thymeleaf.prefix=classpath:/templates/ # Prefix that gets prepended to view names when building a URL.
443443
spring.thymeleaf.reactive.max-chunk-size= # Maximum size of data buffers used for writing to the response, in bytes.
444-
spring.thymeleaf.reactive.media-types=text/html # Media types supported by the view technology.
444+
spring.thymeleaf.reactive.media-types= # Media types supported by the view technology.
445445
spring.thymeleaf.servlet.content-type=text/html # Content-Type value written to HTTP responses.
446446
spring.thymeleaf.suffix=.html # Suffix that gets appended to view names when building a URL.
447447
spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain.

0 commit comments

Comments
 (0)