Skip to content

Commit

Permalink
fix: 커스텀 어노테이션 + Qualifier로 버그 수정
Browse files Browse the repository at this point in the history
REF: #5
  • Loading branch information
CODe5753 committed Apr 17, 2022
1 parent 8fe85aa commit 7a06e07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/java/hello/core/annotation/MainDiscountPolicy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hello.core.annotation;

import org.springframework.beans.factory.annotation.Qualifier;

import java.lang.annotation.*;

@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Qualifier("mainDiscountPolicy")
public @interface MainDiscountPolicy {
}
2 changes: 2 additions & 0 deletions src/main/java/hello/core/discount/FixDiscountPolicy.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package hello.core.discount;

import hello.core.annotation.MainDiscountPolicy;
import hello.core.member.Grade;
import hello.core.member.Member;
import org.springframework.stereotype.Component;

@Component
@MainDiscountPolicy
public class FixDiscountPolicy implements DiscountPolicy {

private int discountFixAmount = 1000; // 1000원 할인
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hello/core/order/OrderServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hello.core.order;

import hello.core.annotation.MainDiscountPolicy;
import hello.core.discount.DiscountPolicy;
import hello.core.member.Member;
import hello.core.member.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -14,7 +14,7 @@ public class OrderServiceImpl implements OrderService {
private final DiscountPolicy discountPolicy;

@Autowired
public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) {
public OrderServiceImpl(MemberRepository memberRepository, @MainDiscountPolicy DiscountPolicy discountPolicy) {
this.memberRepository = memberRepository;
this.discountPolicy = discountPolicy;
}
Expand Down

0 comments on commit 7a06e07

Please sign in to comment.