-
XML로 정의된 Bean 호출하기개발 2012. 12. 5. 12:02반응형
정의 된 빈 호출 하기
1. BeanFactory 사용 (XmlBeanFactory 사용은 deprecated 되었음)
예1) 파일 시스템 기반
Resource resource = new FileSystemResource("src/main/resources/spring/app-context.xml");
BeanFactory factory = new XmlBeanFactory(resource);예2) 클래스 패스 기반
ClassPathResource resource2 = new ClassPathResource("spring/app-context.xml");
BeanFactory factory2 = new XmlBeanFactory(resource2);
2. ApplicationContext 사용
예1) 하나의 설정 파일 사용할 경우
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring/app-context.xml");예2) 여러개의 설정 파일 사용할 경우
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"spring/app-context.xml"});환경
Eclipse + Spring 3.1 + Maven
반응형'개발' 카테고리의 다른 글
Commons IO의 파일 및 디렉터로 변경에 대한 모니터링 기능 사용 (0) 2013.02.01 JGropus의 사용자 프로토콜(헤더) 정의 하는 방법 (0) 2013.02.01 JGroups를 이용하여 메시지 전송시 주의점 (0) 2013.02.01 embedded-database 사용하기 (4) 2012.12.12 Annotation로 정의된 Bean 호출하기 (0) 2012.12.05