Skip to Content
Suffering builds character

6.사용예시 3

스프링 컨테이너에서 특정 Bean 객체를 조회하는 과정

ApplicationContext를 통해 생성된 스프링 컨테이너에서 특정 Bean을 조회할 때

MyRoom.java
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class MyRoom { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("constructor-config.xml"); // getBean()의 인수로 TapeReader.class 타입 전달 TapeReader reader = context.getBean(TapeReader.class); reader.test(); ((ClassPathXmlApplicationContext) context).close(); } }
Last updated on