WebMvcConfiguration 컨트롤러에서 요청하여 웹 리소스로 한 번 더 매핑 작업
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
@Configuration
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {
@Value("${file.data}")
private String dataFolder;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**")
.addResourceLocations("classpath:/static/css/")
.setUseLastModified(false)
.setCacheControl(CacheControl.noCache());
registry.addResourceHandler("/js/**")
.addResourceLocations("classpath:/static/js/")
.setUseLastModified(false)
.setCacheControl(CacheControl.noCache());
registry.addResourceHandler("/data/**")
.addResourceLocations(dataFolder);
}
}
application-dev.properties 화일 fild.data 내용 추가
file.data=file:///D:/dev/web/
실제 저장되는 위치는 D:/dev/web 폴더이지만 웹상에서 출력할때에는 http://localhost:8080/data/ 주소로 출력할수 있다
'Spring boot' 카테고리의 다른 글
Spring Boot - localhost에 도메인(hosts) 연결하여 SSL 적용 (0) | 2024.12.27 |
---|---|
gradlew bootRun Profile 옵션 추가 (1) | 2024.12.27 |
Spring Boot 스케줄러 @Scheduled 어노테이션 사용 (0) | 2023.10.27 |
Spring Boot + WebSocket + UDP 데이터 통신 (0) | 2023.07.18 |
Spring Boot + build.gradle + WebSocket 연동 (0) | 2023.07.17 |