11package com .back .global .config ;
22
3+ import org .springframework .beans .factory .annotation .Value ;
34import org .springframework .context .annotation .Bean ;
45import org .springframework .context .annotation .Configuration ;
56import org .springframework .data .domain .PageRequest ;
67import org .springframework .data .web .config .PageableHandlerMethodArgumentResolverCustomizer ;
8+ import org .springframework .web .servlet .config .annotation .ResourceHandlerRegistry ;
9+ import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
710
811/**
912 * 웹 관련 설정을 정의하는 구성 클래스.
13+ * - 페이징 설정
14+ * - 정적 리소스 매핑 (로컬 이미지 서빙)
1015 */
1116@ Configuration
12- public class WebConfig {
17+ public class WebConfig implements WebMvcConfigurer {
18+
19+ @ Value ("${ai.image.storage-type:local}" )
20+ private String storageType ;
21+
22+ @ Value ("${ai.image.local-storage-path:./uploads/images}" )
23+ private String localStoragePath ;
1324
1425 // 스프링의 페이지 요청을 1부터 시작하도록 설정
1526 // 최대 페이지 크기 및 기본 페이지 설정
@@ -21,4 +32,18 @@ public PageableHandlerMethodArgumentResolverCustomizer customizer() {
2132 pageableResolver .setFallbackPageable (PageRequest .of (0 , 5 ));
2233 };
2334 }
35+
36+ /**
37+ * 정적 리소스 핸들러 설정
38+ * 로컬 개발 환경에서만 /images/** 경로를 로컬 파일 시스템에 매핑
39+ * S3 환경에서는 S3 URL을 직접 사용하므로 이 설정 불필요
40+ */
41+ @ Override
42+ public void addResourceHandlers (ResourceHandlerRegistry registry ) {
43+ if ("local" .equals (storageType )) {
44+ registry .addResourceHandler ("/images/**" )
45+ .addResourceLocations ("file:" + localStoragePath + "/" )
46+ .setCachePeriod (3600 ); // 1시간 캐싱
47+ }
48+ }
2449}
0 commit comments