java, spring

WARN Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)

isaac.kim 2023. 5. 8.
728x90
반응형

Spring Boot에서 발견되는 다음과 같은 오류 메시지가 확인되었습니다.

 

 

# 오류

 

WARN ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)

 

 

 

 

# 해결 방법 1

오류 메시지의 내용을 확인하면 해결할 수 있는데요.

 

project>src>main>resources>templates

 

templates 폴더를 생성해주시거나 or 뒤에 옵션을 설정해주는 방법으로 해결할 수 있을 것 같습니다.

 

 

반응형

 

위 해결 방식은 templates 폴더를 생성하여서 오류를 해결하였고,

경고 메시지 없이 실행되는 것을 확인할 수 있습니다.

 

# 해결 방법 2

위 오류 메시지에서 처럼 set spring.thymeleaf.check-template-location=false 을 해주어서 해결할 수도 있습니다.

 

application.yml 파일에 다음과 같이 세팅합니다.

spring:
  thymeleaf:
    check-template-location: false

 

 

주관적으로는 템플릿 엔진을 사용할 때는 FE 부분만 나누어서 관리할 수 있도록

명시하여 관리하는 편이 좋은 거 같아서 true 값으로 세팅하는 것이 좋은 것 같습니다.

 

spring:
  thymeleaf:
    prefix: classpath:/templates/thymeleaf/
    check-template-location: true
    cache: false
    suffix: .html

 

위와 같이 설정한다면 폴더 구조를 다음과 같이 설정합니다.

 

resources>templates>thymeleaf 

 

index.html 과 같은 html 파일은 thymeleaf 폴더 하위에 두고 사용하시면 됩니다.

728x90
반응형