Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...