spring resource handling

Edit

Spring resource handling 예제프로젝트

    String location = devMode ? "file:///" + getProjectRootRequired() + "/client/src/" : "classpath:static/";

sagan의 빌드 파일

sagan-client

이전 방식

sagan-site

applicationDefaultJvmArgs = [
  // Set SAGAN_HOME env variable to the root of sagan project. This allows to register an additional
  // resource handler location and serve static resources directly from the sagan-client module during dev.
  // See sagan.ClientResourcesConfig
  "-DSAGAN_HOME=${rootProject.rootDir}"
]
@Configuration
@Profile(SaganProfiles.STANDALONE)
class ClientResourcesConfig extends WebMvcConfigurerAdapter {

      @Value("${SAGAN_HOME:}")
  private String saganPath;

      @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      if (!this.saganPath.isEmpty()) {
          registry.addResourceHandler("/**")
                  .addResourceLocations("file:///" + this.saganPath + "/sagan-client/src/")
                  .setCachePeriod(0);
      }
  }
}

Spring boot의 디폴트 동작

*.jar의 static 폴더에 있는 자원을 자동으로 등록

spring.resources.static-locations 로 수정 가능

spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ # Locations of static resources.

Cache 전략

웹의 정적 리소스의 버전 명시를 통한 캐시 전략