• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

Unsatisfied dependency 오류 질문

23.07.14 19:32 작성 조회수 2.23k

0

학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.

1. 강의 내용과 관련된 질문을 남겨주세요.
2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.
(자주 하는 질문 링크: https://bit.ly/3fX6ygx)
3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.
(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)

질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예)

[질문 내용]

안녕하세요.

[스프링 데이터 JPA] 이전 까지는 테스트 코드를 실행하는데 있어서 오류가 나지 않았습니다. 그러나, 해당 목차 강의를 듣고 아래와 같은 오류가 발생했습니다.

 

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberController' defined in file [C:\Users\Administrator\Desktop\Inflearn\hello-spring\hello-spring\out\production\classes\hello\hellospring\controller\MemberController.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'springConfig' defined in file [C:\Users\Administrator\Desktop\Inflearn\hello-spring\hello-spring\out\production\classes\hello\hellospring\SpringConfig.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'springDataJpaMemberRepository' defined in hello.hellospring.repository.SpringDataJpaMemberRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract java.util.List hello.hellospring.repository.MemberRepository.findALL(); Reason: Failed to create query for method public abstract java.util.List hello.hellospring.repository.MemberRepository.findALL(); No property 'findALL' found for type 'Member'

 


해당 오류를 통해 MemberRepository 인터페이스의 findALL 메서드에 문제가 있는 것 같은데, 도통 원인을 못찾겠습니다..

 

아래는 SpringConfig 클래스의 코드와, 강의를 들으며 커밋한 제 깃허브 레포지토리를 첨부했습니다.

 

감사합니다.

 

[SpringConfig.class]

package hello.hellospring;

import hello.hellospring.repository.*;
import hello.hellospring.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//직접 Bean에 넣는 방법
@Configuration
public class SpringConfig {

    private final MemberRepository memberRepository;

    @Autowired
    public SpringConfig(MemberRepository memberRepository) {
        this.memberRepository = memberRepository;
    }


    @Bean
    public MemberService memberService() {
        return new MemberService(memberRepository);
    }

}

https://github.com/beomth/Inflearn-spring

 

답변 1

답변을 작성해보세요.

0

y2gcoder님의 프로필

y2gcoder

2023.07.15

안녕하세요. 버럼님, 공식 서포터즈 y2gcoder입니다.

말씀해주신 원인과 코드 모두 살펴보았습니다!

사실 원인은 굉장히 단순합니다. findAll()의 이름이 맞지 않아서 그렇습니다. Spring Data JPA 라이브러리에서 는 JpaRepository<Entity, PkType>을 상속하는 Repository 인터페이스를 만들면, 애플리케이션을 구동할 때 자동으로 CRUD 기본 기능이 포함된 구현체를 만들어주고 있습니다. 문제는 기본 기능 중에서는 findAll()도 포함되어 있다는 것입니다. 아무래도 자동으로 만들어주는 Spring Data JPA 라이브러리의 특성 때문인지 자신들이 만들 메서드의 이름과 대소문자가 다르면 이러한 에러를 뱉는 것을 종종 볼 수 있었습니다. 그래서 영한님 께서도 MemberRepository 인터페이스를 만들 때 findAll()로 만드신 것을 보실 수 있습니다.

이와 별개로도 가급적 자바의 메서드에 대한 네이밍 규칙은 카멜 케이스라고 합니다. 카멜 케이스에서는 첫 시작은 소문자, 연결되는 단어의 앞글자만 대문자로 하는 것을 원칙으로 합니다. 이러한 부분에 따라 많은 라이브러리들, 다른 개발자들이 코딩하고 있으니 가급적이면 이러한 원칙을 따라서 코딩해주시는 것이 좋습니다 :)

MemberRepository 인터페이스의 findALL() 을 findAll()로 바꿔주시고 다른 구현체들도 바꿔주시면 애플리케이션을 정상적으로 구동하실 수 있습니다!

감사합니다.

버럼님의 프로필

버럼

질문자

2023.07.17

와...진짜 너무너무 감사합니다 ㅠㅠㅠ