작성
·
324
0
package hello.core.member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class MemberServiceImpl implements MemberService {
//private final MemberRepository memberRepository = new MemoryMemberRepository();
private final MemberRepository memberRepository;
@Autowired
public MemberServiceImpl(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}
@Override
public void join(Member member){
memberRepository.save(member);
}
@Override
public Member findMember(Long memberId){
return memberRepository.findById(memberId);
}
//싱글톤 test용
public MemberRepository getMemberRepository() {
return memberRepository;
}
}
basicScan 테스트를 진행하는데 코드를 몇 번씩 비교했는데 저렇게 떠서 왜인지 찾다가 https://www.inflearn.com/questions/799379/nosuchbeandefinitionexception-no-qualifying-bean-of-type-x27-hello-core-member
이 사이트에서 OMG님이 제공해주신 test코드
@Test
void basicScan() {
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AutoAppConfig.class);
System.out.println("================");
String[] beanDefinitionNames = ac.getBeanDefinitionNames();
for(String beanDefinitionName : beanDefinitionNames) {
BeanDefinition beanDefinition = ac.getBeanDefinition(beanDefinitionName);
if (beanDefinitionName.contains("memberService")) {
if(beanDefinition.getRole() == BeanDefinition.ROLE_APPLICATION) {
System.out.println("beanDefinitionName : " + beanDefinitionName +
" beanDefinition : " + beanDefinition);
}
}
}
System.out.println("================");
// MemberService memberService = ac.getBean(MemberService.class);
// assertThat(memberService).isInstanceOf(MemberService.class);
}
를 돌리면 제공해주신 출력 예시대로 나오는데 ,정작 강의에서 해주시는 Test코드는 계속 에러가 나고 있습니다 ㅠㅠㅠ
어떻게 해결해야할까요..?