자바
[spring] thymleaf 배포 시 template might not be accessible 문제
blaxsior
2024. 5. 29. 12:30
IDE에서는 아무 문제가 없지만, jar 파일로 만들어 배포하니 타임리프 템플릿을 찾지 못하는 문제가 발생했다.
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
타임리프 리졸버는 classpath:/templates/을 기본 prefix로 사용한다. 만약 th:replace 또는 th:insert로 템플릿을 참조할 때 경로 앞에 "/"을 붙이면 "//"으로 처리되어 경로 인식에 실패한다고 한다.
모든 템플릿 경로 앞에 "/"을 빼면 문제가 해결된다.
<footer th:replace="~{/layout/footer :: footer}">푸터</footer>
<!-- 위를 아래로 -->
<footer th:replace="~{layout/footer :: footer}">푸터</footer>