Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
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
Today
Total
관리 메뉴

[IT]Zero-MG

[Thymeleaf::타임리프] 배포 후 생긴 오류 2가지 해결 본문

프론트 기록/Thymeleaf

[Thymeleaf::타임리프] 배포 후 생긴 오류 2가지 해결

민1009 2023. 10. 3. 01:36

 

현재 프론트 단을 Thymeleaf로 개발중인 개인 프로젝트가 하나 있다.

 

해당 프로젝트를 진행하면서 로컬(local) 환경에서 테스트 했을 때 아무 문제가 없이 잘 됬는데

이상하게 상용서버에 배포를 한 후 2가지 문제가 생겼다.

 

포스팅을 위해.. 해결 후 2가지 오류를 다시 시연!

 

 

첫번째 오류,

문제의 페이지에 들어가면

위 이미지처럼 화이트라벨 에러(Whitelabel Error)가 나오게 되었다...

 

디버깅 콘솔에는 아래같은 오류가 출력되었다.

 

[THYMELEAF][http-nio-8080-exec-6] Exception processing template "member/approval": An error happened during template parsing (template: "class path resource [templates/member/approval.html]")

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/member/approval.html]")
        at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.15.RELEASE.jar!/:3.0.15.RELEASE]
        at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.15.RELEASE.jar!/:3.0.15.RELEASE]

 

 

뭐가 문제인지 유심히 보다 보니

' An error happened during template parsing ' 라는 문구를 보게 되었다..

Thymeleaf 구문 오류구나 싶어서 어디가 문제인지 열심히 삽질하며 확인 하다보니..

header와 footer를 나누어서 불러들이던 구문쪽에 th:replace 경로가 문제인 걸 확인했다.

 

현재

<th:block th:replace="~{/layout/header :: header}"></th:block>

위와같이 절대경로로 되어 있는 것을 지워준다.

 

<th:block th:replace="~{layout/header :: header}"></th:block>

경로 앞 부분에 '/'를 제거해서 위와같은 경로로 바꿔주었다.

[ /layout/header  -->  layout/header ]

 

왜 이렇게 해야지 해결이 됬을까?

답은 간단하다.

기본 경로로 인식하길 'resources/templates/' 이런식으로 앞에 붙여서 경로인식을 하게 되는데,

오류가 났던 상태로 이어 붙이면 'resources/templates//layout/header' 가 되버린다.

중간에 /가 한개 더 들어가서 경로가 이상해 지는 것이다.

 

변경된 경로로 이어 붙여보면 'resources/templates/layout/header' 이렇게 잘 맞아 떨어진다.

이렇게 해서 배포 전에 잘못 되어있던 부분들을 모두 수정해 준 뒤 해당 오류를 안보게 되었다.

 

 

두번째 오류,

 

이 오류도 마찬가지로 문제의 페이지에 들어가면 화이트라벨이 나온다.

 

디버깅 콘솔에는 아래와 같이 표시된다.

 

[THYMELEAF][http-nio-8080-exec4] Exception processing template "/member/blockStatus": Error resolving template [/member/blockStatus], template might not exist or might not be accessible by any of the configured Template Resolvers

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [/member/blockStatus], template might not exist or might not be accessible by any of the configured Template Resolvers

 

이번엔 해당 페이지에 액세스를 못한다고 한다..

 

산넘어 산이로다..

 

오류를 잘 읽어보니.. 'template might not exist or might' ....?

템플릿이 존재하지 않을 수 있단다... 분명 있는데 이상하다... 생각하며

Controller를 슬쩍 봐보니

 

return 경로에 맨앞 '/'가 문제였다.

return "member/blockStatus";

이렇게 변경 해주니 html을 잘 찾아서 연결해서 보여주었다.

이 문제도 마찬가지로 똑같이 '//'가 2개 들어가서 경로 인식을 못한 문제이다.

 

 

Thymeleaf는 항상 경로를 유의깊게 잘 보면서 개발해야 할 것 같다.

 

이 문제 해결방법이 다른분들께도 도움이 되길 바라며 포스팅은 이만 마치도록 하겠다.

제가 소비한 시간을 다른분들이 또 소비하지 않길 바라며..

다들 잘 해결 되셨길...