더북(TheBook)

그런 다음 이 장의 이전 예제에서 사용한 것과 동일한 방식으로 Main 클래스에서 스프링이 앵무새 빈의 참조를 올바르게 주입했음을 증명할 것이다.

public class Main {

    public static void main(String[] args) {
        var context = 
            new AnnotationConfigApplicationContext(ProjectConfig.class);

        Person p = context.getBean(Person.class);

        System.out.println("Person's name: " + p.getName());
        System.out.println("Person's parrot: " + p.getParrot());
    }
}

앱 콘솔에는 다음 표시된 출력과 유사한 내용이 인쇄될 것이다. 출력의 두 번째 줄은 Koko라는 앵무새가 Ella라는 사람 빈의 소유임을 증명한다.

Person's name: Ella
Person's parrot: Parrot : Koko
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.