SpringBoot, thymeleaf 로 페이지를 만들어서 AWS EC2 (linux) 에 배포한 후에 페이지를 호출하면 아래와 같이 thymleaf를 읽을 수 없다는 에러가 발생합니다.
에러메세지
Exception processing template "admin/index": Error resolving template [/admin/layout/header], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "admin/layout/layout" - line 206, col 6)
해결방법
1. Template 경로 바꾸기
application.yml 파일에 template 경로를 추가 합니다.
spring:
thymeleaf:
prefix: classpath:/templates/
2. Controller 반환값 수정
Controller의 반환값 맨 앞에 "/"가 들어가 있으면 안됩니다. (잘못된 예 => return "/admin/index";)
@Slf4j
@Data
@Controller
public class AdminMainController {
@GetMapping("/admin")
public String adminRoot(Model model) {
model.addAttribute("menuActive", "main");
return "admin/index";
}
}
3. thymeleaf 경로변경
thymeleaf에서 fragment, replace를 사용시에 th:replace 경로 맨 앞 "/"를 넣으면 안됩니다.
<기존 소스>
layout.html
<!-- 내비게시션바(상단메뉴) Start -->
<nav th:replace="/admin/layout/header :: headerFragment"></nav>
<!-- 내비게시션바(상단메뉴) End -->
header.html
<header th:fragment="headerFragment"></header>
<변경 소스>
layout.html
<!-- 내비게시션바(상단메뉴) Start -->
<nav th:replace="admin/layout/header :: headerFragment"></nav>
<!-- 내비게시션바(상단메뉴) End -->
header.html
<header th:fragment="headerFragment"></header>
'AWS' 카테고리의 다른 글
Git pull, push 할 때 username, password 생략하기 (0) | 2024.03.20 |
---|---|
AWS EC2 인스턴스에 SpringBoot 프로젝트 배포 (0) | 2024.03.20 |
Amazon Linux 2023에서 Java 11 설치하기 (0) | 2023.09.04 |
Amazon Linux 2023에서 MySQL 명령줄 클라이언트를 설치 (0) | 2023.09.04 |
텍스트를 여러 나라 언어로 자동 번역하는 서비스 (0) | 2023.08.29 |