2009-11-07 11 views
2

파일 시스템의 컨텍스트와 클래스 경로에서 ApplicationContext를 한 번에 가져 오는 방법이 있습니까? FileSystemXmlApplicationContext를 사용하고 ClassPathXmlApplicationContext를 사용하고 fileSystemApplicationContext를 부모로 전달하는 대신응용 프로그램 컨텍스트 얻기

답변

3

org.springframework.context.support.GenericApplicationContext을 살펴 보시기 바랍니다. org.springframework.beans.factory.xml.XmlBeanDefinitionReader과 함께 사용하면 원하는 유연성을 얻을 수 있습니다. XmlBeanDefinitionReader은 또한 다음 적절한 리소스를 처리 할 수 ​​org.springframework.core.io.ResourceLoader를 사용하는 방법 loadBeanDefinitions(String)을 가지고

GenericApplicationContext ctx = new GenericApplicationContext(); 
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); 
xmlReader.loadBeanDefinitions(new ClassPathResource("classpathContext.xml")); 
xmlReader.loadBeanDefinitions(new FileSystemResource("fileSystemContext.xml")); 

참고 :처럼 보일 것 GenericApplicationContext's javadoc

귀하의 코드에 코드 예제가있다. 어떤 경우 코드는 다음과 같습니다.

GenericApplicationContext ctx = new GenericApplicationContext(); 
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); 
xmlReader.loadBeanDefinitions("classpath:classpathContext.xml")); 
xmlReader.loadBeanDefinitions("file:fileSystemContext.xml")); 
관련 문제