일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
- AWS 생성
- CI/CD
- 깃허브 연동
- css 리셋
- dbeaver 백업/복구
- 배포 자동화
- 소프트웨어
- .ppk
- reset
- EL1021E
- ..gitignore
- 배열 call by value
- 자바 swing 프로젝트
- Jenkins
- Node Property
- Quartz dependency
- firstChild
- deploy.sh
- Quartz 라이브러리
- 되돌리기
- document 함수
- 환경변수
- submit 기본동작
- git 폴더 모으기
- 타임리프 참조 오류
- 테스팅
- 클래스 참조
- 깃허브 토큰 생성
- 깃허브 토큰 발급
- 채팅 프로젝트
- Today
- Total
TY blog
타임리프 클래스 필드 참조 오류 본문
타임리프 템플릿을 적용하여 개인 웹 사이트 개발을 진행하는 도중
An error happened during template parsing
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1021 E: A problem occurred whilst attempting to access the property 'projectNum': 'Accessing member 'projectNum' is forbidden for type 'class com.sun.springprofile_v2.model.ProjectVO' in this expression context.'
위와 같은 서버 오류를 발견하였는데
@Getter
@ToString
public class ProjectVO {
private int projectNum;
private String main_img;
private String title;
}
VO 코드
<div class="project_box" th:each="item : ${list}" th:onclick="|goPage('project/detail?num=${item.projectNum}')|">
<span th:text="${item.title}"></span>
<img th:src="${item.main_img}" />
</div>
HTML 타임리프 코드 일부분
Controller에서는 Model 객체에
ProjectVO를 리스트로 넘겨주는 코드였고
Private 필드로 되어 있어도 @Getter 어노테이션이 있어 참조를 할 수 있어야 정상인데
HTML 코드 부분에서 클래스의 필드를 참조하지 못해 오류가 발생했다.
원인을 찾던 중 문서를 확인해 보니
https://www.thymeleaf.org/doc/articles/thymeleaf31whatsnew.html
Thymeleaf 3.1: What’s new and how to migrate - Thymeleaf
Thymeleaf 3.1: What’s new and how to migrate Latest version is Thymeleaf 3.1.1.RELEASE. What’s new Support for Servlet API 5.0 and the jakarta.* class namespace Thymeleaf 3.1 adds support for the new jakarta.* class namespace in the Servlet API since v
www.thymeleaf.org
타임리프 문서에 내용을 보면
이러한 패키지의 클래스와 정적 참조에 대해 메서드/생성자 호출이 금지됩니다.
라는 내용이 있는데
내가 만든 vo 경로에 패키지 부분은 com.sun.springprofile_v2.model 이였으며
패키지 경로가 com.sun.* 으로 되어 있어서 클래스의 필드를 참조하지 못했던 것이다.
패키지 이름을 수정 후 다시 실행해 보니
해결이 되었다.