Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring-boot thymeleaf load HTML file from classpath

I've a multi module project structure like :

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

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

and on my controller:

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

I'm getting the error message as below:

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

Is there configuration needed to configure something specially for spring for searching templates on class path?

like image 695
aymeba Avatar asked Apr 06 '15 20:04

aymeba


People also ask

Is Thymeleaf still popular?

While Thymeleaf is more of a template engine for server-side application development. But Thymeleaf's popularity is on a steady rise. The developer community is slowly moving away from 'once a common' MVC framework for Javascript-based development.


1 Answers

Adding following properties solves my problem:

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
like image 170
aymeba Avatar answered Sep 20 '22 13:09

aymeba