🛠️Backend/오류해결

[Thyme Leaf] org.thymeleaf.exceptions.templateinputexception: error resolving template 오류

뉴발자 2024. 12. 20.
728x90

 

 

 

 

 

 

 

 

 

 

 

 

 

 

[Thyme Leaf] org.thymeleaf.exceptions.templateinputexception: error resolving template 오류

 

 

에러 상황

프로젝트를 다른 직원과 협업으로 진행하게 됐고 웹 사이트를 Thyme Leaf로 만들게 됐다.

 

로컬 서버에서는 잘 접속되던 사이트가 AWS 서버에 올린 후 접속 시 403 에러가 발생했다.

 

 

에러 코드

org.thymeleaf.exceptions.templateinputexception: error resolving template...

 

 

해결 방법

해당 에러는 타임리프에서 지정된 경로의 템플릿을 못찾으면서 발생한 오류이다.

 

그래서 두 가지 작업을 해주었다.

 

1. @GetMapping의 value 값의 맨 앞 "/" 제거

@GetMapping("/index") // ❌

@GetMapping("index") // ✅

 

위와 같은 value 값을 설정하면 타임 리프에서 절대 경로를 찾기 때문에 localhost:8080//index 의 경로로 사이트를 조회하게 된다.

 

2. html 파일 안에서 layout:decorate 옵션으로 html 파일을 찾을 때 경로의 맨 앞 "/" 제거

layout:decorate="~{/common/layout}" // ❌

layout:decorate="~{common/layout}" // ✅

 

1번과 동일하게 html 파일 안의 경로도 절대 경로를 찾기 때문에 "/" 값을 제거해줘야한다.

 

 

 

 

 

 

 

 

 

 

728x90

댓글