Commit 7e7acea5 authored by Phillip Webb's avatar Phillip Webb

Don't check for /templates when using groovy-all

Update GroovyTemplateAutoConfiguration so that the `/template`
folder check only occurs when the groovy-all jar is not being
used.

Fixes gh-2190
See gh-1915
parent 6ad23b1c
......@@ -18,6 +18,9 @@ package org.springframework.boot.autoconfigure.groovy.template;
import groovy.text.markup.MarkupTemplateEngine;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import javax.annotation.PostConstruct;
import javax.servlet.Servlet;
......@@ -75,7 +78,7 @@ public class GroovyTemplateAutoConfiguration {
@PostConstruct
public void checkTemplateLocationExists() {
if (this.properties.isCheckTemplateLocation()) {
if (this.properties.isCheckTemplateLocation() && !isUsingGroovyAllJar()) {
Resource resource = this.resourceLoader.getResource(this.properties
.getPrefix());
Assert.state(resource.exists(), "Cannot find template location: "
......@@ -85,6 +88,28 @@ public class GroovyTemplateAutoConfiguration {
}
}
/**
* MarkupTemplateEngine could be loaded from groovy-templates or groovy-all.
* Unfortunately it's quite common for people to use groovy-all and not actually
* need templating support. This method checks attempts to check the source jar so
* that we can skip the {@code /template} folder check for such cases.
* @return true if the groovy-all jar is used
*/
private boolean isUsingGroovyAllJar() {
try {
ProtectionDomain domain = MarkupTemplateEngine.class
.getProtectionDomain();
CodeSource codeSource = domain.getCodeSource();
if (codeSource != null
&& codeSource.getLocation().toString().contains("-all")) {
return true;
}
}
catch (Exception ex) {
}
return false;
}
@Bean
@ConditionalOnMissingBean(GroovyMarkupConfig.class)
@ConfigurationProperties(prefix = "spring.groovy.template.configuration")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment