2010-12-28 6 views
2
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
       "application-context.xml")); 

내 응용 프로그램-context.xml에 내가이 오류는로드하는 방법을로드 응용 프로그램의 context.xml

...

INFO - XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [application-context.xml] 
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [application-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [application-context.xml] cannot be opened because it does not exist 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73) 
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61) 
    at com.mysticcoders.mysticpaste.services.CrudService.main(CrudService.java:9) 
Caused by: java.io.FileNotFoundException: class path resource [application-context.xml] cannot be opened because it does not exist 
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:141) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) 
    ... 4 more 

com.myname.mysubpackage.spring.application-context.xml 내부에 존재한다.

답변

3
new XmlBeanFactory(new ClassPathResource(
       "application-context.xml")); 

파일은 기본 패키지에 직접 있어야합니다. 당신이 받는다는을 사용하는 경우

후 가장 좋은 장소가 문제가있는 경우 클래스 경로의 대안이 있지만 권장하지 않습니다 (같은 파일 시스템에서 상황에 맞는 파일을 호출 할 수 있습니다 이해 디렉토리 resource

+0

주요 리소스로 이동하면 dir이 완벽하게 작동합니다. 감사. –

0

에 넣어하는 것입니다, 일시적 문제) 해결 :

File file = new File("/path/" + "Test.xml"); 
FileSystemResource fileResource = new FileSystemResource(file); 
XmlBeanFactory mFactory = new XmlBeanFactory(fileResource); 

을하지만 최선의 사용은 자원 디렉토리에 설정 파일을 넣어 클래스 패스에이 디렉토리를 추가하는 것입니다. Maven을 사용하면 정의하기가 쉽습니다.

관련 문제