inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 핵심 원리 - 기본편

다양한 설정 형식 지원 - 자바 코드, XML

에러관련 질문드려요~

1490

김아영

작성한 질문수 2

0

안녕하세요. 강사님. 이번 강의에서 

XmlAppContext.java는

package hello.beanfind;

import hello.core.member.MemberRepository;
import hello.core.member.MemberService;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.test.context.web.GenericXmlWebContextLoader;

public class XmlAppContext {

@Test
@DisplayName("xml config 테스트해보기")
void xmlAppContext(){
ApplicationContext ac = new GenericXmlApplicationContext("appConfig.xml");
MemberService ms = ac.getBean("memberService", MemberService.class);
Assertions.assertThat(ac).isInstanceOf(MemberService.class);
}

}

appConfig.xml은 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="memberService" class="hello.core.member.MemberServiceImpl" >
<constructor-arg name="memberRepository" ref="memberRepository" />
</bean>
<bean id="memberRepository" class="hello.core.member.MemoryMemberRepository" />


<bean id="orderService" class="hello.core.order.OrderServiceImpl">
<constructor-arg name="memberRepository" ref="memberRepository" />
<constructor-arg name="discountPolicy" ref = "discountPolicy" />
</bean>
<bean id="discountPolicy" class="hello.core.discount.RateDiscountPolicy"/>


</beans>

이렇게 작성하였는데 아래와 같은 에러가 나는데요. 

18:22:00.364 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'memberService'

18:22:00.397 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'memberRepository'

18:22:00.420 [main] WARN org.springframework.context.support.GenericXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberService' defined in class path resource [appConfig.xml]: Unsatisfied dependency expressed through constructor parameter 0: Ambiguous argument values for parameter of type [hello.core.member.MemberRepository] - did you specify the correct bean references as arguments?

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberService' defined in class path resource [appConfig.xml]: Unsatisfied dependency expressed through constructor parameter 0: Ambiguous argument values for parameter of type [hello.core.member.MemberRepository] - did you specify the correct bean references as arguments?

구글링을 해도 원인을 모르겠어서요..ㅜ.ㅜ

oop spring

답변 2

6

김아영

알려주신 대로 생성자부분을 보니 생성자부분의 이름이 달라서 그랬던 거였네요..ㅜ.ㅜ 오히려 이렇게 에러가 나니 당연하게 여겼던 부분까지 다시보게 되네요~ 답변 감사드립니다^-^

3

김영한

안녕하세요. 아영님

MemberService 객체의 생성자 부분에 문제가 있는 것 같아요. 해당 객체 전체를 보여주시겠어요?

SingletonService가 JVM이 뜰 때 생성되는게 맞나요?

0

29

1

섹션3. 11 회원객체 다이어그램

0

37

1

OCP, DIP과 @Qualifier 어노테이션에 대해서 질문합니다.

0

36

1

코드 자료

0

81

2

구현체가 동적으로 정해질 때, 팩토리 기법을 사용하나요?

0

82

2

MemberService의 인터페이스를 왜 사용하는지 궁금합니다.

0

98

1

롬복 @Setter를 써야 하는 상황이 있는건가요?

0

104

1

빈 등록 메서드의 파라미터가 빈이 아니어도 되나요?

0

88

1

테스트 속도가 나중에 영향이 있을까요?

0

91

1

gradle 설정 안떠서 질문 남깁니다!

0

141

2

build.gradle로 프로젝트를 여는 이유

0

100

1

provider 사용하는 이유

0

97

1

다음 강의 뭘 들어야 할까요

0

139

2

프로토타입 빈, 직접 destroy 호출 안 할 경우

0

70

1

beanB

0

91

2

퀴즈다시풀기

0

76

1

Gradle로 바꿔도 오류가 똑같이 발생하네요 ㅠㅠ

0

102

2

"중복 등록과 충돌" 강의에서 강사님과 다른 에러가 발생합니다.

0

71

3

run 실행했는데 결과창이 이렇게 뜨네요 왜 그런건가요>

0

113

2

도메인의 정의?

0

63

1

ApplicationContext 질문입니다.

0

68

1

@Scope의 proxyMode를 사용할때 단위 테스트 방법

0

98

2

ai api 선정하기 관련 질문

0

136

2

생성자 자동주입 관련해서

0

70

1