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
This commit is contained in:
Brian Clozel
2017-05-12 14:43:05 +02:00
parent 89c284cb13
commit 4a47c1eff8
3 changed files with 8 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.thymeleaf;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.PostConstruct;
@@ -55,6 +56,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.MediaType;
import org.springframework.util.MimeType;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
@@ -252,8 +254,10 @@ public class ThymeleafAutoConfiguration {
ThymeleafReactiveViewResolver resolver = new ThymeleafReactiveViewResolver();
resolver.setTemplateEngine(templateEngine);
resolver.setDefaultCharset(this.properties.getEncoding());
resolver.setSupportedMediaTypes(
this.properties.getReactive().getMediaTypes());
final List<MediaType> mediaTypes = this.properties.getReactive().getMediaTypes();
if (mediaTypes != null) {
resolver.setSupportedMediaTypes(mediaTypes);
}
resolver.setExcludedViewNames(this.properties.getExcludedViewNames());
resolver.setViewNames(this.properties.getViewNames());
if (this.properties.getReactive().getMaxChunkSize() > 0) {

View File

@@ -17,8 +17,6 @@
package org.springframework.boot.autoconfigure.thymeleaf;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -227,8 +225,7 @@ public class ThymeleafProperties {
/**
* Media types supported by the view technology.
*/
private List<MediaType> mediaTypes = new ArrayList<>(
Collections.singletonList(MediaType.TEXT_HTML));
private List<MediaType> mediaTypes;
public List<MediaType> getMediaTypes() {
return this.mediaTypes;

View File

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