강의에서는 다 같은 값으로 나오는데, 저는 왜 다른값으로 나올까요? ㅠ
package hello.core.member;
public class MemberServiceImpl implements MemberService {
private final MemberRepository memberRepository;
public MemberServiceImpl(MemoryMemberRepository memoryMemberRepository) {
this.memberRepository = memoryMemberRepository;
}
@Override
public void join(Member member) {
memberRepository.save(member);
}
@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId);
}
//테스트용도
public MemberRepository getMemberRepository(){
return memberRepository;
}
}
package hello.core.member;
public class MemberServiceImpl implements MemberService {
private final MemberRepository memberRepository;
public MemberServiceImpl(MemoryMemberRepository memoryMemberRepository) {
this.memberRepository = memoryMemberRepository;
}
@Override
public void join(Member member) {
memberRepository.save(member);
}
@Override
public Member findMember(Long memberId) {
return memberRepository.findById(memberId);
}
//테스트용도
public MemberRepository getMemberRepository(){
return memberRepository;
}
}
package hello.core.order;
import hello.core.discount.DiscountPolicy;
import hello.core.member.Member;
import hello.core.member.MemberRepository;
public class OrderServiceImpl implements OrderService{
private final MemberRepository memberRepository;
private final DiscountPolicy discountPolicy;
public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) {
this.memberRepository = memberRepository;
this.discountPolicy = discountPolicy;
}
@Override
public Order createOrder(Long memberId, String itemName, int itemPrice) {
Member member = memberRepository.findById(memberId);
int discountPrice = discountPolicy.discount(member, itemPrice);
return new Order(memberId, itemName, itemPrice, discountPrice);
}
public MemberRepository getMemberRepositoryO() {
return memberRepository;
}
}
강의코드
안녕하세요. 궁금증연구소님, 공식 서포터즈 OMG입니다.
바로 다음 강의에서도 설명해주시지만, AppConfig에
@Configuration
어노테이션이 누락될 경우 싱글톤을 보장하지 않아 겪으신 상황과 동일한 상황이 발생할 수 있습니다.AppConfig클래스를 확인해주세요.
그리고 @Bean 등록 시
static
키워드가 포함되어 있다면 이 때도 싱글톤을 보장하지 않으니 같이 확인해주세요 😀감사합니다.
답글