작성
·
472
0
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예)
[질문 내용]
여기에 질문 내용을 남겨주세요.
오류 로그 Failed to load ApplicationContext for [MergedContextConfiguration@65ae095c testClass = hello.core.CoreApplicationTests, locations = [], classes = [hello.core.CoreApplication], contextInitializerClasses = [], activeProfiles = [], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@4ef37659, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@306cf3ea, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@52102734, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4d910fd6, org.springframework.boot.test.context.SpringBootTestAnnotation@930cd593], contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
강의의 3분 30초 경 오류 코드를 수정하는 순서에서의 AutoAppConfig클래스의 3줄을 주석처리 하는 부분을 처리 하였는데도 오류가 떠서 GPT에 검색을 해보니까 주석 처리를 했는데도 memoryMemberRepository Bean이 두개가 등록이 되어있다고 나옵니다.
AutoAppCofig 코드
package hello.core;
import hello.core.member.MemberRepository;
import hello.core.member.MemoryMemberRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
@Configuration
@ComponentScan(
excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Configuration.class)
)
public class AutoAppConfig {
// @Bean("memoryMemberRepository")
// MemberRepository memberRepository() {
// return new MemoryMemberRepository();
// }
}
MemberServiceImpl 코드
package hello.core.member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@Component
public class MemberServiceImpl implements MemberService{
private final MemberRepository memberRepository;
@Autowired // ac.getBean(MemberRepository.class)
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);
}
//테스트 용도
public MemberRepository getMemberRepository() {
return memberRepository;
}
}
MemberService 코드
package hello.core.member;
public interface MemberService {
void join(Member member);
Member findMember(Long memberId);
}
MemoryMemberRepository 코드
package hello.core.member;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class MemoryMemberRepository implements MemberRepository{
private static Map<Long, Member> store = new HashMap<>();
@Override
public void save(Member member) {
store.put(member.getId(), member);
}
@Override
public Member findById(Long memberId) {
return store.get(memberId);
}
}