Skip to content

Commit b07fdce

Browse files
committed
[Refactor] 로컬이미지ë경로설정
1 parent d4cfebd commit b07fdce

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

back/src/main/java/com/back/global/config/WebConfig.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package com.back.global.config;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
56
import org.springframework.data.domain.PageRequest;
67
import 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

Comments
 (0)