org.springframework.beans.factory.UnsatisfiedDependencyException
작업 상태
- 스프링으로 파일첨부 작업을 하던중, Controller쪽에 있던 설정을 Service쪽으로 옮긴후에 발생한 에러입니다.
- Controller에서는 동작하던 상태였습니다.
- application.properties 설정 upload.folder=, 실제 위치 확인 완료
에러 메시지
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'fileUploadController' defined in file
Unsatisfied dependency expressed through constructor parameter 0
원인
Spring 컨텍스트가 아직 초기화되지 않은 상태에서 StorageService 인스턴스가 생성되어서 발생하는 문제입니다.
처리
에러발생상태 코드
처리 상태
@PostConstruct 어노테이션이 붙은 메서드는 해당 클래스의 인스턴스 생성 및 DI가 완료된 후, 초기화 작업을 수행하기 위해 호출되는 메서드입니다.
@Value 어노테이션을 사용하면, 스프링 컨테이너가 빈을 생성할 때 주입하려는 값을 설정 파일(application.properties 또는 application.yml) 등 외부의 설정 파일에서 가져와서 주입할 수 있습니다.
참고
Getting Started | Uploading Files (spring.io)
Spring | Home
Cloud Your code, any cloud—we’ve got you covered. Connect and scale your services, whatever your platform.
spring.io