mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
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:
parent
f12b3fbcd7
commit
969c7d6fa1
11
spring-bootstrap-cli/samples/ui.groovy
Normal file
11
spring-bootstrap-cli/samples/ui.groovy
Normal 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";
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -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");
|
||||
|
11
spring-bootstrap-cli/src/test/resources/css/bootstrap.min.css
vendored
Normal file
11
spring-bootstrap-cli/src/test/resources/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
25
spring-bootstrap-cli/src/test/resources/templates/home.html
Normal file
25
spring-bootstrap-cli/src/test/resources/templates/home.html
Normal 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>
|
@ -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 {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user