Make sure ThymeleafAutoConfiguration works if imported directly

Before this change if Layout dialect not available then the nested class is
loaded and barfs because it depended on the layout dialect (in a
@ConditionalOnClass annotation).
This commit is contained in:
Dave Syer 2013-05-31 16:16:19 +01:00
parent f12b3fbcd7
commit 969c7d6fa1
6 changed files with 73 additions and 3 deletions

View File

@ -0,0 +1,11 @@
@Grab("org.thymeleaf:thymeleaf-spring3:2.0.16")
@Controller
class Example {
@RequestMapping("/")
public String helloWorld(Map<String,Object> model) {
model.putAll([title: "My Page", date: new Date(), message: "Hello World"])
return "home";
}
}

View File

@ -62,9 +62,19 @@ TARGETDIR=target/classes
if [ -f build.gradle ]; then
TARGETDIR=build/classes/main
fi
mkdir -p "${TARGETDIR%/}"
if [ -f ${TARGETDIR} ]; then
if [ "${CLASSPATH}" == "" ]; then
CLASSPATH="${TARGETDIR}"
else
CLASSPATH="${CLASSPATH}":"${TARGETDIR}"
fi
fi
CLASSPATH="${CLASSPATH}":"${SPRING_BIN}":"${TARGETDIR}"
if [ "${CLASSPATH}" == "" ]; then
CLASSPATH="${SPRING_BIN}"
else
CLASSPATH="${CLASSPATH}":"${SPRING_BIN}"
fi
for f in "${SPRING_HOME}"/classes "${SPRING_HOME}"/*.jar "${SPRING_HOME}"/lib/*.jar; do
[ -f $f ] && CLASSPATH="${CLASSPATH}":$f

View File

@ -127,6 +127,19 @@ public class SampleIntegrationTests {
assertEquals("World!", result);
}
@Test
public void uiSample() throws Exception {
// To run this one from the command line you need to add target/test-classes to
// CLASSPATH
start("samples/ui.groovy");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertTrue("Wrong output: " + result, result.contains("Hello World"));
result = FileUtil.readEntirely(new URL(
"http://localhost:8080/css/bootstrap.min.css").openStream());
assertTrue("Wrong output: " + result, result.contains("container"));
}
@Test
public void actuatorSample() throws Exception {
start("samples/actuator.groovy");

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="${title}">Title</title>
<link rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}"
href="../../resources/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="http://www.thymeleaf.org"> Thymeleaf -
Plain </a>
<ul class="nav">
<li><a th:href="@{/}" href="home.html"> Home </a></li>
</ul>
</div>
</div>
<h1 th:text="${title}">Title</h1>
<div th:text="${message}">Fake content</div>
<div id="created" th:text="${#dates.format(date)}">July 11,
2012 2:17:16 PM CDT</div>
</div>
</body>
</html>

View File

@ -116,7 +116,7 @@ public class ThymeleafAutoConfiguration {
}
@Configuration
@ConditionalOnClass({ LayoutDialect.class })
@ConditionalOnClass(name = "nz.net.ultraq.web.thymeleaf.LayoutDialect")
@ConditionalOnMissingBean(SpringTemplateEngine.class)
protected static class ThymeleafWebLayoutConfiguration {