작성
·
165
0
안녕하세요!
컴포넌트 스캔의 필터와 관련하여 질문이 있어 올립니다!
기존에 있던 AppConfig.java로 등록한 Bean을 제외하려고 excludeFilters를 사용했는데, CoreApplication을 실행하면
Parameter 0 of constructor in hello.core.member.MemberServiceImpl required a single bean, but 2 were found:
- memoryMemberRepository: defined in file [파일경로/core/out/production/classes/hello/core/member/MemoryMemberRepository.class]
- memberRepository: defined by method 'memberRepository' in class path resource [hello/core/AppConfig.class]
이런 오류가 뜹니다. 코드는 다음과 같습니다.
package hello.core;
import hello.core.discount.DiscountPolicy;
import hello.core.discount.FixDiscountPolicy;
import hello.core.discount.RateDiscountPolicy;
import hello.core.member.MemberRepository;
import hello.core.member.MemberService;
import hello.core.member.MemberServiceImpl;
import hello.core.member.MemoryMemberRepository;
import hello.core.order.OrderService;
import hello.core.order.OrderServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig {
@Bean
public MemberRepository memberRepository() {
return new MemoryMemberRepository();
}
@Bean
public MemberService memberService() {
return new MemberServiceImpl(memberRepository());
}
@Bean
public DiscountPolicy discountPolicy() {
//return new FixDiscountPolicy();
return new RateDiscountPolicy();
}
@Bean
public OrderService orderService() {
return new OrderServiceImpl(memberRepository(), discountPolicy());
}
}
package hello.core;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import static org.springframework.context.annotation.ComponentScan.*;
@Configuration
@ComponentScan(
excludeFilters = @Filter(type = FilterType.ANNOTATION, classes = Configuration.class)
)
public class AutoAppConfig {
}
위의 오류는 memberRepository뿐만 아니라 rateDiscountPolicy에서도 나옵니다. @Component와 @Autowired 어노테이션은 잘 설정한것 같은데 뭐가 문제일까요?