Spring & Spring Boot

[Spring Boot/Error] Thymeleaf layout 적용 안되는 문제 해결

토발자 2024. 4. 25. 18:00
반응형

간단하게 새로운 토이 프로젝트를 만들어보려고 한다.

 

프론트는 Thymeleaf를 이용하는데 Thymeleaf layout을 적용하는데 문제가 생긴 것 같다.

 

꽤 며칠을….이걸로 골머리를 앓다가..

정말 어이없게 해결하게 되어서..기록해둔다.

 


 

문제 발생

Thymeleaf layout을 적용하는데 뭔가 이상하다.

우선 버전은 다음과 같다.

  • Java 17
  • Spring Boot 3

공통 레이아웃을 만들어두고 사용하고자 하는데 적용이 안된다.

 

gradle 파일에서 의존성을 확인하고, 공통 레이아웃 파일들의 경로에도 문제가 없는데..

dependencies{

    ...
    
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation group: 'com.github.zhanhb', name: 'thymeleaf-layout-dialect', version: '2.5.3'
    
    ...
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/common_layout}">

...

 

구글링을 하면 layout:decorator 가 deprecated 되었으니 layout:decorate로 변경해야 한다는 내용이 가장 많이 나오는데 이 부분도 잘 적용되어 있다.

 

문제 해결

어이없게도 이 문제는 dependency에 있었다.

dependencies{

    ...
    
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect' // 수정한 부분
    
    ...
}

 

이렇게 thymeleaf-layout-dialect 의존성 부분을 바꾸니 잘 된다….

반응형