Study/SpringBoot
Spring Boot에서 외부 경로 매핑
오늘만 사는 여자
2020. 11. 20. 14:54
728x90
반응형
Spring Boot에서 외부 경로 매핑하기
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/video_view/**")
.addResourceLocations("file:/DATA/video/"); //리눅스 root에서 시작하는 폴더 경로
}
}
//윈도우일 경우 아래처럼 사용하면 된다.
addResourceLocations("file:///D:/DATA/video/");
1) addResourceHandler : URL path 지정
- 위의 설정 대로 했을 경우 localhost8080/images 와 같이 됩니다.
2) addResourceLocations : 이미지가 업로드 될 실제 경로
- 반드시 경로의 마지막은 "/"와 같이 끝나야 합니다.
- 만약 images/ 로 끝나지 않고 images로 끝날 경우 정상적으로 설정이 되지 않습니다.
참조 :
toshi15shkim.github.io/articles/2019-09/spring-resources-location
Spring boot에서 외부 경로 매핑하기 | Toshi의 개발 블로그
프로젝트 외부 폴더 경로 매핑 방법
toshi15shkim.github.io
blog.naver.com/PostView.nhn?blogId=yjhyjh5369&logNo=222010922119
728x90
반응형