Add spring.*.enabled for MVC view resolvers
Since we use a composite ViewResolver glbally by default it can be awkward to switch off the view technology that you have on the classpath but aren't actually using.
This commit is contained in:
@@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -134,6 +135,7 @@ public class FreeMarkerAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "freeMarkerViewResolver")
|
||||
@ConditionalOnProperty(name = "spring.freemarker.enabled", matchIfMissing = true)
|
||||
public FreeMarkerViewResolver freeMarkerViewResolver() {
|
||||
FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
|
||||
this.properties.applyToViewResolver(resolver);
|
||||
|
||||
@@ -48,10 +48,23 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
|
||||
*/
|
||||
private String[] templateLoaderPath = new String[] { DEFAULT_TEMPLATE_LOADER_PATH };
|
||||
|
||||
/**
|
||||
* Switches off MVC view resolution if set to false (default true).
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
public FreeMarkerProperties() {
|
||||
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public Map<String, String> getSettings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -103,6 +104,7 @@ public class GroovyTemplateAutoConfiguration {
|
||||
@ConditionalOnClass({ Servlet.class, LocaleContextHolder.class,
|
||||
UrlBasedViewResolver.class })
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnProperty(name = "spring.groovy.template.enabled", matchIfMissing = true)
|
||||
public static class GroovyWebConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -50,6 +50,19 @@ public class GroovyTemplateProperties extends AbstractViewResolverProperties {
|
||||
*/
|
||||
private Map<String, Object> configuration = new HashMap<String, Object>();
|
||||
|
||||
/**
|
||||
* Switches off MVC view resolution if set to false (default true).
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -175,6 +176,7 @@ public class ThymeleafAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "thymeleafViewResolver")
|
||||
@ConditionalOnProperty(name = "spring.thymeleaf.enabled", matchIfMissing = true)
|
||||
public ThymeleafViewResolver thymeleafViewResolver() {
|
||||
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
|
||||
resolver.setTemplateEngine(this.templateEngine);
|
||||
|
||||
@@ -76,6 +76,19 @@ public class ThymeleafProperties {
|
||||
*/
|
||||
private String[] excludedViewNames;
|
||||
|
||||
/**
|
||||
* Switches off MVC view resolution if set to false (default true).
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isCheckTemplateLocation() {
|
||||
return this.checkTemplateLocation;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -124,6 +125,7 @@ public class VelocityAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "velocityViewResolver")
|
||||
@ConditionalOnProperty(name = "spring.velocity.enabled", matchIfMissing = true)
|
||||
public VelocityViewResolver velocityViewResolver() {
|
||||
VelocityViewResolver resolver = new VelocityViewResolver();
|
||||
this.properties.applyToViewResolver(resolver);
|
||||
|
||||
@@ -71,10 +71,23 @@ public class VelocityProperties extends AbstractTemplateViewResolverProperties {
|
||||
*/
|
||||
private boolean preferFileSystemAccess = true;
|
||||
|
||||
/**
|
||||
* Switches off MVC view resolution if set to false (default true).
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
public VelocityProperties() {
|
||||
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getDateToolAttribute() {
|
||||
return this.dateToolAttribute;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.View;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.support.RequestContext;
|
||||
import org.springframework.web.servlet.view.groovy.GroovyMarkupConfig;
|
||||
import org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver;
|
||||
@@ -100,6 +101,15 @@ public class GroovyTemplateAutoConfigurationTests {
|
||||
assertThat(response.getContentType(), equalTo("text/html;charset=UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disableViewResolution() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.groovy.template.enabled:false");
|
||||
registerAndRefreshContext();
|
||||
assertThat(this.context.getBeanNamesForType(ViewResolver.class).length,
|
||||
equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localeViewResolution() throws Exception {
|
||||
registerAndRefreshContext();
|
||||
|
||||
Reference in New Issue
Block a user