작성
·
1.3K
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?
구글링을 해도 원인을 모르겠어서요..ㅜ.ㅜ