From 0f17142366c6bf9e8bc20b261b24caa210107108 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 30 Oct 2014 15:18:39 +0000 Subject: [PATCH] Make GroovyWebConfiguration conditional on spring-webmvc's availability GroovyWebConfiguration creates a GroovyTemplateViewResolver which is a UrlBasedViewResolver sub-class. UrlBasedViewResolver is provided by spring-webmvc. Previously, if a user configured a web application but did not have spring-webmvc on the classpath, the application would fail to start with a NoClassDefFoundError for UrlBasedViewResolver. This commit makes GroovyWebConfiguration conditional on UrlBasedViewResolver being on the classpath so that it backs of in the absence of spring-webmvc. Fixes gh-1793 --- .../groovy/template/GroovyTemplateAutoConfiguration.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java index 4b31f742c80..4a32921fc94 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java @@ -47,6 +47,7 @@ import org.springframework.core.Ordered; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; +import org.springframework.web.servlet.view.UrlBasedViewResolver; /** * Autoconfiguration support for Groovy templates in MVC. By default creates a @@ -54,6 +55,7 @@ import org.springframework.core.io.ResourceLoader; * can override that by providing a {@link TemplateEngine} of a different type. * * @author Dave Syer + * @author Andy Wilkinson * @since 1.1.0 */ @Configuration @@ -144,7 +146,8 @@ public class GroovyTemplateAutoConfiguration { } @Configuration - @ConditionalOnClass({ Servlet.class, LocaleContextHolder.class }) + @ConditionalOnClass({ Servlet.class, LocaleContextHolder.class, + UrlBasedViewResolver.class }) @ConditionalOnWebApplication public static class GroovyWebConfiguration {