hanker

Spring boot - thymeleaf layout 사용 시 설정 (layout 적용 안될 때) 본문

SPRING

Spring boot - thymeleaf layout 사용 시 설정 (layout 적용 안될 때)

hanker 2025. 4. 2. 02:49
반응형

Spring boot에서 분명히 thymeleaf 의존성을 설정해 주고 layout을 사용했는데 layout 적용이 안된다.

 

아래 글에서 해결 방법을 알아보자.

 

 


dependency 설정

 

1. 최초 프로젝트 셋팅할때에 설정하거나, pom.xml 또는 gradle에 추가해 준다.

의존성 설정

<!-- pom.xml -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>


<!-- build.gradle -->
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")

- 최초 설정 시 이렇게만 추가하고 layout을 사용해 보면 layout이 적용이 안되는데, layout을 사용하기 위해서는 추가 의존성 주입을 해줘야 한다.

 

 

 

2. 추가 의존성 주입

<!-- pom.xml -->
<dependency>
    <groupId>nz.net.ultraq.thymeleaf</groupId>
    <artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

<!-- build.gradle -->
implementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect")

- Spring Boot 프로젝트에서는 이 의존성만 추가하면 자동으로 설정되고, 별도의 설정 클래스는 없다.

- Thymeleaf Layout Dialect를 추가하게 되면 layout:decoratelayout:fragment와 같은 레이아웃 관련 속성을 제공한다.

반응형