programing

클래스 경로에서 HTML 파일을 로드하는 스프링 부트 타임리프

starjava 2023. 7. 11. 21:23
반응형

클래스 경로에서 HTML 파일을 로드하는 스프링 부트 타임리프

저는 다음과 같은 다중 모듈 프로젝트 구조를 가지고 있습니다.

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

언급URL : https://stackoverflow.com/questions/29479403/spring-boot-thymeleaf-load-html-file-from-classpath

반응형