본문 바로가기

자바

[spring] thymleaf 배포 시 template might not be accessible 문제

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>

'자바' 카테고리의 다른 글

[spring] @Sql 어노테이션  (0) 2024.08.08
[spring] 메일 송신 기능 테스트(GreenMail)  (0) 2024.05.29
[spring] 외부 설정 사용  (0) 2024.05.24