Relax requirement for groovy template directory to exist

Since groovy-templates is included with groovy-all it is unreasonable
to expect anyone who has it on their classpath to have resolvable templates.
We may need to revisit this decision, but since the origain feature
that drove this was thymeleaf and idaiotic users having it on their
classpath but not using it, maybe we don't need to.
pull/890/head
Dave Syer 11 years ago
parent 15303a2de6
commit f572992c5d

@ -24,7 +24,6 @@ import groovy.text.markup.TemplateConfiguration;
import java.net.URL;
import java.net.URLClassLoader;
import javax.annotation.PostConstruct;
import javax.servlet.Servlet;
import org.springframework.beans.factory.BeanClassLoaderAware;
@ -44,7 +43,6 @@ 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.util.Assert;
/**
* Autoconfiguration support for Groovy templates in MVC. By default creates a
@ -66,17 +64,6 @@ public class GroovyTemplateAutoConfiguration {
@Autowired
private GroovyTemplateProperties properties;
@PostConstruct
public void checkTemplateLocationExists() {
if (this.properties.isCheckTemplateLocation()) {
Resource resource = this.resourceLoader.getResource(this.properties
.getPrefix());
Assert.state(resource.exists(), "Cannot find template location: " + resource
+ " (please add some templates "
+ "or check your FreeMarker configuration)");
}
}
@Configuration
@ConditionalOnClass({ Servlet.class, LocaleContextHolder.class })
@ConditionalOnWebApplication
@ -108,8 +95,15 @@ public class GroovyTemplateAutoConfiguration {
}
private ClassLoader createParentLoaderForTemplates() throws Exception {
return new URLClassLoader(new URL[] { this.resourceLoader.getResource(
this.properties.getPrefix()).getURL() }, this.classLoader);
Resource resource = this.resourceLoader.getResource(this.properties
.getPrefix());
if (resource.exists()) {
return new URLClassLoader(new URL[] { resource.getURL() },
this.classLoader);
}
else {
return this.classLoader;
}
}
@Bean

@ -43,7 +43,7 @@ public class GroovyTemplateProperties {
private String[] viewNames;
private boolean checkTemplateLocation = true;
private boolean checkTemplateLocation = false;
private TemplateConfiguration configuration = new TemplateConfiguration();

@ -44,5 +44,6 @@ org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration
# Template availability providers
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.web.JspTemplateAvailabilityProvider

@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.autoconfigure.groovy.template.web.GroovyTemplateViewResolver;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.i18n.LocaleContextHolder;
@ -75,12 +74,6 @@ public class GroovyTemplateAutoConfigurationTests {
assertThat(this.context.getBean(GroovyTemplateViewResolver.class), notNullValue());
}
@Test(expected = BeanCreationException.class)
public void nonExistentTemplateLocation() {
registerAndRefreshContext("spring.groovy.template.prefix:"
+ "classpath:/does-not-exist/");
}
@Test
public void emptyTemplateLocation() {
new File("target/test-classes/templates/empty-directory").mkdir();

Loading…
Cancel
Save