IT/Framework

스프링부트(SpringBoot)에서 재시작 없이 정적소스(html, js, css) 변경 적용하기

돔찌 2019. 9. 21. 15:38

보통 웹프로젝트를 어딘가에서 내려받든, 과거에 본인이 어떤 설정을 했든 당연 시 하게 정적소스를 변경하고 브라우저를 새로고침하면 반영되었다.

그러나 SpringBoot 프로젝트를 새로만들고 아무런 설정을 하지 않는다면 변경된 정적소스가 브라우저 상 새로고침으로도 반영되지 않는다.

아래의 간단한 설정을 적용하여 정적소스(html, js, css)를 적용시킨다.


 

# Step 1 : devtools 라이브러리 장착

우선 Maven 및 Gradle에 아래 dependency 에 추가하여 devtools을 내려받는다.

 

 

<Maven>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <version>2.0.4.RELEASE</version>
</dependency>

 

<Gradle>

// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.4.RELEASE'

 

아래와 같이 devtools 라이브러리가 정상적으로 받아졌는지 확인

 

 

 

 

# Step 2 : application.yml(properties) 파일에 옵션 추가

아래 옵션을 추가해준다.

 

 

<application.yml파일>

spring:
  devtools: 
    livereload:
      enabled: true
  freemarker:
    cache: false
  thymeleaf:
    cache: false

 

 

<application.properties 파일>

spring.devtools.livereload.enabled=true
spring.freemarker.cache=false
spring.thymeleaf.cache=false

 

 

이후 프로젝트를 재시작하면 그 정적소스를 변경하고 저장하면

프로젝트를 재시작하지 않아도 브라우저 상 새로고침으로 변경된 사항이 적용된다.

 

 

 

 


# Step 3 : 그래도 변경된 소스가 적용되지 않는 경우

cache에 false 옵션 줬음에도 여러가지 상황으로 인해 cache가 적용되었을 가능성이 있을 수 있다.

CTRL + F5(cache 날리는 새로고침) 을 해보고도 적용되지 않는다면

(크롬기준) Alt + Shift + n 을 눌러 시크릿모드에서도 CTRL + F5 처리를 해보면 바뀐 소스가 적용되어 나타난다.