Browse Source

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.
pull/2139/head
Dave Syer 11 years ago
parent
commit
8a5f151e47
  1. 2
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java
  2. 13
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerProperties.java
  3. 2
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java
  4. 13
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateProperties.java
  5. 2
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java
  6. 13
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java
  7. 2
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java
  8. 13
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityProperties.java
  9. 10
      spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java

2
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java

@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -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 { @@ -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);

13
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerProperties.java

@ -48,10 +48,23 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties @@ -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;
}

2
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java

@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -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 { @@ -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

13
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateProperties.java

@ -50,6 +50,19 @@ public class GroovyTemplateProperties extends AbstractViewResolverProperties { @@ -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;
}

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

@ -29,6 +29,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -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 { @@ -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);

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

@ -76,6 +76,19 @@ public class ThymeleafProperties { @@ -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;
}

2
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java

@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -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 { @@ -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);

13
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityProperties.java

@ -71,10 +71,23 @@ public class VelocityProperties extends AbstractTemplateViewResolverProperties { @@ -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;
}

10
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java

@ -38,6 +38,7 @@ import org.springframework.mock.web.MockHttpServletResponse; @@ -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 { @@ -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();

Loading…
Cancel
Save