프로그래밍/Spring
available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations 오류
개발계발게발
2022. 4. 5. 14:44
반응형
available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations
로젝트 내부 코드에서 Beans의 생성자를 찾거나 정의하지 못하는 경우
1. @Service 어노테이션 확인
@Repository
@Controller
2. dispatcher-servlet.xml 수정
component-scan 설정
3. 오토와이어링을 시도하는 과정에서 빈 없는 경우 처리 방법
자동 주입 대상 옵션 처리
- @Autowired(required=false) : 자동 주입할 대상이 없으면 수정자 메서드 자체가 호출 X
- org.springframework.lang.@Nullable : 자동 주입할 대상이 없으면 null이 입력
- Optional<> : 자동 주입할 대상이 없으면 Optional.empty가 입력
반응형