더북(TheBook)

예제 3-8 구성 클래스에서 Parrot 타입 빈 정의하기

@Configuration
@ComponentScan(basePackages="beans")
public class ProjectConfig {

    @Bean
    public Parrot parrot1() {
        Parrot p = new Parrot();
        p.setName("Koko");
        return p;
    }

    @Bean
    public Parrot parrot2() { ← 현재 설정에서는 parrot2라는 이름의 빈이 Person 빈에 주입된다. 
        Parrot p = new Parrot();
        p.setName("Miki");
        return p;
    }
} 
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.