Thymeleaf에서 TemplateInputException 발생의 원인

주의

이 문건은 과거 Hexo 블로그 (2018-06-08) 에서 이동된 문서입니다.

시간이 지남에 따라 최신 기술과 다를 수 있으니 주의 바랍니다.



org.thymeleaf.exceptions.TemplateInputException 발생…

Spring Boot의 프로젝트를 진행하던 중 화면을 하나 추가하고 서버를 올린 뒤 해당 뷰로 접근하는 순간…
아래와 같은 에러가 발생하였다.

2018-05-28 01:31:59 [ERROR] [TemplateEngine.java]process(1085) : [THYMELEAF][https-jsse-nio-8081-exec-7] Exception processing template "/views/stat/schedule": Error resolving template "/views/stat/schedule", template might not exist or might not be accessible by any of the configured Template Resolvers

2018-05-28 01:31:59 [ERROR] [DirectJDKLog.java]log(181) : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/views/stat/schedule", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/views/stat/schedule", template might not exist or might not be accessible by any of the configured Template Resolvers

여기서 org.thymeleaf.exceptions.TemplateInputException 이 에러를 보지 못해서 계속 뷰에 뭔가를 잘못 입력했나 싶어서 계속 thymeleaf 화면 파일을 계속 찾다가 도저히 못찾아서 검색해본 결과…

문제는 Controller 영역의 view 화면 지정하는 곳이 문제였다.
자세한 것은 아래 코드를 참고!

ModelAndView mv = new ModelAndView();
//mv.setViewName("/views/stat/schedule"); //뷰 파일 앞에 /를 붙이는게 문제
mv.setViewName("views/stat/schedule");

Written by@MHLab
로또는 흑우집합소 🎲
와인관리, 시음노트, 셀러관리는 마와셀 🥂

🫥 My Service|  📜 Contact|  💻 GitHub