From 9b121dcbaa0e5df77477390240143bee0769f548 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 7 Apr 2016 10:55:38 +0100 Subject: [PATCH] Make MustacheViewResolver extend AbstractTemplateViewResolver The Mustache support should still be usable outside a web application because the properties only use web stuff in that context and don't have any field or method signatures that depend on web. Fixes gh-5626 --- .../mustache/MustacheAutoConfiguration.java | 6 +----- .../autoconfigure/mustache/MustacheProperties.java | 12 ++++++++++-- .../mustache/web/MustacheViewResolver.java | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java index d5ca090278..6668bf5d77 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java @@ -113,11 +113,7 @@ public class MustacheAutoConfiguration { @ConditionalOnMissingBean(MustacheViewResolver.class) public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler) { MustacheViewResolver resolver = new MustacheViewResolver(); - resolver.setPrefix(this.mustache.getPrefix()); - resolver.setSuffix(this.mustache.getSuffix()); - resolver.setCache(this.mustache.isCache()); - resolver.setViewNames(this.mustache.getViewNames()); - resolver.setContentType(this.mustache.getContentType().toString()); + this.mustache.applyToViewResolver(resolver); resolver.setCharset(this.mustache.getCharsetName()); resolver.setCompiler(mustacheCompiler); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java index bcff487896..1dea5ce309 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheProperties.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.mustache; -import org.springframework.boot.autoconfigure.template.AbstractViewResolverProperties; +import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @since 1.2.2 */ @ConfigurationProperties(prefix = "spring.mustache") -public class MustacheProperties extends AbstractViewResolverProperties { +public class MustacheProperties extends AbstractTemplateViewResolverProperties { public static final String DEFAULT_PREFIX = "classpath:/templates/"; @@ -42,18 +42,26 @@ public class MustacheProperties extends AbstractViewResolverProperties { */ private String suffix = DEFAULT_SUFFIX; + public MustacheProperties() { + super(DEFAULT_PREFIX, DEFAULT_SUFFIX); + } + + @Override public String getPrefix() { return this.prefix; } + @Override public void setPrefix(String prefix) { this.prefix = prefix; } + @Override public String getSuffix() { return this.suffix; } + @Override public void setSuffix(String suffix) { this.suffix = suffix; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java index 2dff6de83b..6cc66e9b12 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/web/MustacheViewResolver.java @@ -29,7 +29,7 @@ import org.springframework.beans.propertyeditors.LocaleEditor; import org.springframework.core.io.Resource; import org.springframework.web.servlet.View; import org.springframework.web.servlet.ViewResolver; -import org.springframework.web.servlet.view.UrlBasedViewResolver; +import org.springframework.web.servlet.view.AbstractTemplateViewResolver; /** * Spring MVC {@link ViewResolver} for Mustache. @@ -39,7 +39,7 @@ import org.springframework.web.servlet.view.UrlBasedViewResolver; * @author Phillip Webb * @since 1.2.2 */ -public class MustacheViewResolver extends UrlBasedViewResolver { +public class MustacheViewResolver extends AbstractTemplateViewResolver { private Compiler compiler = Mustache.compiler();