Spring-boot thymeleaf从classpath加载HTML文件

时间:2015-04-06 20:47:10

标签: java spring spring-boot

我有一个多模块项目结构,如:

- application (parent module)
--- boot (web-app)
----- src/main/resources/templates/layout.html

---- todo (jar file)
----- src/main/resources/templates/home.html

并在我的控制器上:

@RequestMapping(value = "/home")
public String home() {
    return "todo/home";
}

我收到如下错误消息:

Error resolving template "todo/home", template might not exist or
might not be accessible by any of the configured Template 
Resolvers]

是否需要配置专门用于spring的内容以便在类路径上搜索模板?

更新

解决。添加以下属性可以解决我的问题:

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

1 个答案:

答案 0 :(得分:12)

添加以下属性可以解决我的问题:

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false