[Spring Boot][오류해결] org.springframework.beans.factory.UnsatisfiedDependencyException

2022. 2. 12. 13:00·JAVA/오류해결
org.springframework.beans.factory.UnsatisfiedDependencyException

 

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException

 

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

스프링부트를 사용하다가 위와 같은 에러가 발생하는 경우가 있다.

특정 인터페이스를 상속한 클래스 파일이 여러 개일 때

의존성 주입을 위해 @Qualifier 어노테이션을 사용하게 되는데, 이 때 실수를 하면 발생하는 에러다.

 

 

아래와 같은 DAO 파일과  Service 파일 있다고 해보자.

(전제 >>> DAO 인터페이스를 상속한 파일이 여러 개이다.)

 

- DAO 파일

@Repository
public class EmployeeDAOJpaImpl implements EmployeeDAO {

	private EntityManager entityManager;
	
	@Autowired	
	public EmployeeDAOJpaImpl(EntityManager entityManager) {
		this.entityManager = entityManager;
	}
	
	@Override
	public List<Employee> findAll() {
		
		// create a query
		Query query =
				entityManager.createQuery("from Employee");
		
		// execute query and get result list
		List<Employee> employees = query.getResultList();
		
		// return the results
		return employees;

	}
    
    ...
}

 

 

 

문제상황

- Service 파일

@Service
public class EmployeeServiceImpl implements EmployeeService {

	private EmployeeDAO employeeDAO;
	
	@Autowired
	public EmployeeServiceImpl(@Qualifier("EmployeeDAOJpaImpl") EmployeeDAO employeeDAO) {
		this.employeeDAO = employeeDAO;
	}
    
    ...
    
}

 

위 코드에서 무엇이 문제일까?

분명히 @Qualifier 어노테이션에 똑같이 클래스명을 복사붙여넣기해도 해결이 안 된다.

똑같이 복사 붙여넣기한 것이 문제다.

 

 

문제의 코드

public EmployeeServiceImpl(@Qualifier("EmployeeDAOJpaImpl") EmployeeDAO employeeDAO)

 

 

해결방법

public EmployeeServiceImpl(@Qualifier("employeeDAOJpaImpl") EmployeeDAO employeeDAO)

@Qualifier 어노테이션에 클래스명을 적을 때 맨 앞 글자를 소문자로 적어줘야한다.

"EmployeeDAOJpaImpl" 가 아닌 "employeeDAOJpaImpl"으로 수정하면 된다.

'JAVA/오류해결' 카테고리의 다른 글
  • [Spring Boot][오류해결] Parameter 0 of constructor in ~~ required a bean of type ~~ that could not be found.
  • [Spring Boot][오류해결] Parameter 0 of constructor in ~~ required a single bean, but 2 were found
  • [오류해결] Several ports (8005, 8080) required by Tomcat v9.0 Server at localhost are already in use
  • [오류해결] Missing artifact com.fasterxml.jackson.core:jackson-databind:bundle
gakko
gakko
좌충우돌 개발기
  • gakko
    MYVELOP 마이벨롭
    gakko
  • 전체
    오늘
    어제
    • 분류 전체보기 (203)
      • Spring (23)
        • Spring (10)
        • Spring Boot (7)
        • Spring Security (1)
        • Hibernate (4)
      • Test (3)
      • 끄적끄적 (6)
      • 활동 (35)
        • 부스트캠프 (23)
        • 동아리 (3)
        • 컨퍼런스 (3)
        • 글또 (5)
        • 오픈소스 컨트리뷰션 (1)
      • 디자인패턴 (0)
      • Git & GitHub (22)
        • Git (13)
        • Github Actions (1)
        • 오류해결 (5)
        • 기타(마크다운 등) (3)
      • 리눅스 (6)
        • 기초 (6)
        • 리눅스 서버 구축하기 (0)
      • Infra (2)
        • Docker (1)
        • Elastic Search (0)
        • Jenkins (1)
        • AWS (1)
      • MySQL (7)
        • 기초 (6)
        • Real MySQL (1)
      • 후기 (3)
        • Udemy 리뷰 (3)
      • CS (26)
        • 웹 기본지식 (0)
        • 자료구조 (13)
        • 운영체제 OS (12)
        • 데이터베이스 (1)
        • 시스템 프로그래밍 (0)
        • 기타 (0)
      • Tools (1)
        • 이클립스 (1)
        • IntelliJ (0)
      • 프로젝트 (1)
        • 모여모여(부스트캠프) (1)
      • JAVA (32)
        • Maven (6)
        • 오류해결 (11)
        • 자바 클래스&메소드 (1)
        • JSP & Servlet (12)
      • Javascript (5)
        • 기초 (3)
        • React (2)
      • Python (28)
        • 파이썬 함수 (9)
        • 알고리즘 문제풀이 (16)
        • 데이터 사이언스 (2)
        • 웹 크롤링 (1)
      • 단순정보전달글 저장소 (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 우진님
  • 공지사항

  • 인기 글

  • 태그

    Spring
    파이썬
    MySQL
    웹개발
    스프링부트
    Python
    java
    부스트캠프 7기
    자바스크립트
    부스트캠프 멤버십
    부스트캠프
    스프링
    자바
    Git
    jsp
    os
    운영체제
    알고리즘
    오류해결
    GitHub
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
gakko
[Spring Boot][오류해결] org.springframework.beans.factory.UnsatisfiedDependencyException
상단으로

티스토리툴바