Spring Boot에서 외부 정적 경로 확보

1. 환경

– Spring Boot 버전 2.6.2(중요)

2. Spring Boot에서 외부 정적 경로를 설정하는 목적은…

– 파일 업로드 기능을 추가하고 업로드된 위치의 이미지를 URL(예: http://localhost:8080/test.png)로 호출하고 싶은데 bootjar로 빌드할 때 기본 정적 경로는 /입니다. 그래서 내가 원하는 것을 할 수 없습니다.

세 번째 방법

application.properties 파일에 spring.web.resources.static-locations=file:E:/test/를 추가하기만 하면 됩니다.

spring.web.resources.static-locations=file:E:/test/,classpath:/static/

4. 주의사항

많은 블로그가 spring.resources.static-locations에서 이 매개변수를 사용하지만 이 경우 file: 값이 적용되지 않습니다. 스프링 부트 버전의 문제인 것 같습니다. spring.web.resources.static-locations 매개변수를 사용했기 때문에 작동했습니다.