예제 3-6 빈이 두 개 이상 있을 때 매개변수 주입하기1
@Bean
public Person person(Parrot parrot2) { ← 매개변수 이름(parrot2)이 Miki 앵무새의 빈 이름(parrot2)과 일치한다.
Person p = new Person();
p.setName("Ella");
p.setParrot(parrot2);
return p;
}
}
이런 구성으로 앱을 실행하면 다음과 같은 콘솔 출력을 볼 수 있다. 이 앵무새를 나타내는 빈 이름이 parrot2이기 때문에 스프링이 사람 빈을 Miki라는 앵무새에 연결한 것을 관찰할 수 있다(그림 3-12).
Parrot created Parrot created Person's name: Ella Person's parrot: Parrot : Miki