[Thymeleaf, Spring boot] Spring boot Thymeleaf static file 경로 설정 방법

김우진·2022년 9월 7일
0

thymeleaf

목록 보기
1/1

Thymeleaf static file 경로 설정 방법

thymeleaf에서 js나 css 파일을 사용할 때 경로 설정을 하다가 문제가 발생하여 thymeleaf static file 경로 설정 방법에 대해서 찾아보았다.

Spring boot static 웹 콘텐츠 제공

Spring boot는 아래의 폴더에 있는 정적 웹 리소스를 자동으로 추가한다.

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

Thymeleaf static file 경로 설정 방법

잘못된 방법

<link href='/static/fullcalendar/lib/main.css' rel='stylesheet' />
<script src='/static/fullcalendar/lib/main.js'></script>

옳은 방법

<link href='/fullcalendar/lib/main.css' rel='stylesheet' />
<script src='/fullcalendar/lib/main.js'></script>

위의 내용과 같이 Spring boot 는 /resources/나 /static/ 아래의 정적 웹 리소스를 자동으로 추가하므로 thymeleaf 파일에는 /static/ 이후의 내용만 추가해주면된다.

출처

0개의 댓글