interface μ λνμ¬ multiple ν implementation μ΄ μμ λ, μμμ @Qualifier annotation μ μ΄μ©νμ¬ ν΄κ²°νλ€. κ·Έλ¬λ @Primary λΌλ annotation μ μ¬μ©ν΄μλ ν΄κ²°μ΄ κ°λ₯νλ€.
@Primary annotation μ multiple implementation κ°μ΄λ° λ¨ νλλ§ μ¬μ©ν μ μμΌλ©°, λ§μΉ default Bean μΌλ‘μ¨ κΈ°λ₯νλ€. @Qualifier λ₯Ό μ¬μ©νμ¬ νΉμ Bean object λ₯Ό μ§μ νμ§ μλλΌλ Primary λ‘ μ§μ λ Bean μ΄ Injection λλ€.
κ·Έλ¬λ λ§μ½ @Qualifier μ @Primary λ₯Ό λ λ€ μ¬μ©νκ² λ κ²½μ°, @Qualifier κ° λ λμ priority λ₯Ό κ°μ§κΈ° λλ¬Έμ @Qualifier λ§μ λ¨λ
μ μΌλ‘ μ¬μ©νλ κ²μ μΆμ²νλ€. λν multiple Primary μμ μ€λ₯λ₯Ό λ°μμν¨λ€.
Primary - Code
μ°μ Primary λ‘ μ§μ νκ³ μΆμ class μ λνμ¬ @Primary annotation μ μ¬μ©ν΄μ£Όλ©΄ λλ€.
@Component
@Primary
public class FootballCoach implements Coach { ... }κ·Έλ¦¬κ³ Controller μ Constructor Injection μμλ μλμ²λΌ implementation μ΄ νλλ°μ μ‘΄μ¬νμ§ μλ κ²μ²λΌ μ¬μ©ν΄μ£Όλ©΄ λλ€.
// define a constructor for dependency injection
@Autowired
public DemoController(Coach theCoach) {
myCoach = theCoach;
}