개발도구/IDE

intellij에서 static resource(html, js 등) 바로 반영되게 하는 방법 for spring boot

노루아부지 2022. 3. 2. 20:07

Spring boot에서 resources 디렉토리를 수정한 후 그것을 확인하기 위해서는 WAS(Tomcat 등)를 재시작 해야 합니다.

수정 할 때마다 재시작 하는 것은 매우 귀찮은 일입니다.

 

설정 방법

Intellij에서 바로 반영되게 하는 방법은 다음과 같습니다.

 

 

1. build.gradle에 의존성 추가

dependencies {
  ...
  compile('org.springframework.boot:spring-boot-devtools')
}

 

 

2. application 설정파일 수정(yml / properties)

  • 다음은 application.yml의 thymeleaf 사용 예시입니다.
spring:
  devtools:
    livereload:
      enabled: true
  thymeleaf:
    cache: false

 

 

3. Run/Debug Configurations 수정

  1. Run > Edit Configurations 메뉴로 이동
  2. Spring Boot > xxxApplication 선택
  3. On 'Update' action과 On frame deactivation을 Update classes and resources로 변경
    1. 특정 버전 이후에서 설정 방법이 변경되었습니다. 4번 확인 바랍니다.
      Run/Debug Configurations
  4. 변경된 Update classes and resources 설정 방법
    1. Modify options 클릭
      변경된 Update classes and resources 설정 방법
    2. On 'Update' action > Update classes and resources 클릭
      변경된 Update classes and resources 설정 방법
    3. On frame deactivation > Update classes and resources 클릭
      변경된 Update classes and resources 설정 방법

 

 

 

 

4. registry 설정

  1. Ctrl + Shift + A 버튼을 눌러서 Actions 검색창을 Open
  2. registry 검색

  3. Allow auto-make
    1. compiler.automake.allow.when.app.running 항목 체크
    2. Allow auto-make to start even if developed application is currently running 항목 체크
      일정 버전 이후의 intellij에서 `compiler.automake.allow.when.app.running`가  `Allow auto-make to start even if developed application is currently running`로 변경되었습니다.

compiler.automake.allow.when.app.running
Allow auto-make to start even if developed application is currently running

 

 

5. Gradle Build를 Gradle이 아닌 Intellij IDEA로 변경

 

 

이제 WAS를 다시 시작하면 됩니다.

 

만약 그래도 반영이 안된다면

gradle > bootRun이 아닌 SpringBoot의 메인 클래스 파일을 run 하면 됩니다. ( xxxApplication )

728x90
loading