이제 다음 예제에서 볼 수 있듯이, Main 클래스를 작성하고 두 인스턴스의 연결 여부를 확인할 수 있다.
예제 3-2 Main 클래스 정의
public class Main {
public static void main(String[] args) {
var context =
new AnnotationConfigApplicationContext(ProjectConfig.class); ← 구성 클래스(ProjectConfig)를 기반으로 스프링 컨텍스트 인스턴스를 생성한다.
Person person =
context.getBean(Person.class); ← 스프링 컨텍스트에서 Person 빈의 참조를 얻는다.
Parrot parrot =
context.getBean(Parrot.class); ← 스프링 컨텍스트에서 Parrot 빈의 참조를 얻는다.