2015-04-06 106 views
7

我有一个多模块项目结构,如:春季启动thymeleaf加载HTML文件从classpath中

- 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] 

是否有配置需要专门配置一些东西,以便在类路径上搜索模板?

UPDATE

解决。添加以下特性解决了我的问题:

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

你可以发表您的更新是这个问题的答案,并接受它 – 2016-10-17 15:34:08

回答

8

添加以下特性解决了我的问题:

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