【发布时间】:2015-02-19 01:48:25
【问题描述】:
我正在尝试将 Thymeleaf 与 Spring 一起使用,使用 spring-boot。当我访问映射到控制器的 URL 时,我希望会导致使用 Thymeleaf 模板,我只是在浏览器中得到一个空白页面。
我正在使用自动配置,结果如下(摘自@987654321@):
{
"positiveMatches":{
"ThymeleafAutoConfiguration":[
{
"condition":"OnClassCondition",
"message":"@ConditionalOnClass classes found: org.thymeleaf.spring4.SpringTemplateEngine"
}
],
"ThymeleafAutoConfiguration.DefaultTemplateResolverConfiguration":[
{
"condition":"OnBeanCondition",
"message":"@ConditionalOnMissingBean (names: defaultTemplateResolver; SearchStrategy: all) found no beans"
}
],
"ThymeleafAutoConfiguration.ThymeleafDefaultConfiguration":[
{
"condition":"OnBeanCondition",
"message":"@ConditionalOnMissingBean (types: org.thymeleaf.spring4.SpringTemplateEngine; SearchStrategy: all) found no beans"
}
],
"ThymeleafAutoConfiguration.ThymeleafViewResolverConfiguration":[
{
"condition":"OnClassCondition",
"message":"@ConditionalOnClass classes found: javax.servlet.Servlet"
},
{
"condition":"OnWebApplicationCondition",
"message":"found web application StandardServletEnvironment"
}
],
"ThymeleafAutoConfiguration.ThymeleafViewResolverConfiguration#thymeleafViewResolver":[
{
"condition":"OnBeanCondition",
"message":"@ConditionalOnMissingBean (names: thymeleafViewResolver; SearchStrategy: all) found no beans"
},
{
"condition":"OnPropertyCondition",
"message":"matched"
}
],
"ThymeleafAutoConfiguration.ThymeleafWebLayoutConfiguration":[
{
"condition":"OnClassCondition",
"message":"@ConditionalOnClass classes found: nz.net.ultraq.thymeleaf.LayoutDialect"
}
],
},
"negativeMatches":{
"ThymeleafAutoConfiguration.DataAttributeDialectConfiguration":[
{
"condition":"OnClassCondition",
"message":"required @ConditionalOnClass classes not found: com.github.mxab.thymeleaf.extras.dataattribute.dialect.DataAttributeDialect"
}
],
"ThymeleafAutoConfiguration.ThymeleafConditionalCommentsDialectConfiguration":[
{
"condition":"OnClassCondition",
"message":"required @ConditionalOnClass classes not found: org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect"
}
],
"ThymeleafAutoConfiguration.ThymeleafSecurityDialectConfiguration":[
{
"condition":"OnClassCondition",
"message":"required @ConditionalOnClass classes not found: org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"
}
],
}
}
我完全没有应用程序配置——这个阶段的一切都依赖于自动配置。
我的控制器(目前只有一个)如下所示:
@RestController
@RequestMapping("/")
public class MainController {
@RequestMapping(value = "main.html", method = RequestMethod.GET)
public void index( Model model ) {
model.addAttribute( "name", "Gorgonzola" );
}
}
我有以下项目布局:
src/
main/
java/
attendance/
MainController.java
resources/
templates/
main.html
templates/main.html 包含:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Attendance</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
@987654322@ 包括:
"{[/main.html],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}": {
"bean": "requestMappingHandlerMapping",
"method": "public void attendance.MainController.index(org.springframework.ui.Model)"
},
我正在使用 Gradle spring-boot 插件并使用 Gradle bootRun 任务运行应用程序。
我尝试将--debug 添加到bootRun 参数中,当我将浏览器指向@987654323@ 时,我得到了:
2015-02-19 17:36:14.754 DEBUG 9168 --- [tp1565713391-18] o.s.b.a.e.mvc.EndpointHandlerMapping : Looking up handler method for path /main.html
2015-02-19 17:36:14.756 DEBUG 9168 --- [tp1565713391-18] o.s.b.a.e.mvc.EndpointHandlerMapping : Did not find handler method for [/main.html]
...所以我怀疑我缺少一个简单的参数。但它是什么?
谁能看到为什么我的模板没有被处理?或者建议我可以采取的进一步诊断步骤?
【问题讨论】:
标签: spring spring-mvc spring-boot thymeleaf