2012-10-05 4 views
10

의 클래스 패스 리소스를 찾을 수 없습니다.봄은이 같은 조직 프로젝트가 내부 jar 파일

<param-value> 
    /WEB-INF/applicationContext.xml 
</param-value> 

을 그리고 applicationContext.xml에서 내가 가진 : web.xml에서

내가 가진

<import resource="classpath:/company/config/spring-config.xml" /> 

을하지만 실행하면이 오류를 얻을 :

2012-10-04 20:03:39,156 [localhost-startStop-1] springframework.web.context.ContextLoader ERROR: Context initialization failed 
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/company/config/spring-config.xml] 
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [company/config/spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [company/config/spring-config.xml] cannot be opened because it does not exist 
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) 
.... 
Caused by: java.io.FileNotFoundException: class path resource [company/config/spring-config.xml] cannot be opened because it does not exist 
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336) 
... 36 more 

spring-config.xml이에 webapp, 다 잘 작동합니다.

/이 스택 추적의 일부 오류에서 제거 된 것을 확인했으며 이것이 그와 관련이 있는지 궁금합니다.

또한 (불행히도) 저는 Spring 2.5를 사용하고 있습니다.

+1

/company/config/spring-config.xml에서 제거한 다음 – Satya

+0

@Satya를 확인하십시오. 감사합니다. 시도해 보았습니다. 동일한 결과가 나타납니다. – JBCP

+0

@JBCP - 추가적인 문제가 있기 때문에 선행 슬래시를 제거해도 작동하지 않을 수 있지만 선행 슬래시에서는 작동하지 않습니다. 이 기사를 읽으면 도움이 될 것입니다. http://blog.carbonfive.com/2007/05/17/using-classpath-vs-classpath-when-loading-spring-resources/ – GreyBeardedGeek

답변

13

나중에 참조 할 수 있도록 많은 디버깅 후에 문제를 파악했습니다. 그것은 이클립스는 단지 나의 "핵심"라이브러리를 구축하지만, 웹 응용 프로그램 패키지 레이아웃되었다 밝혀, 그래서 대신 내 자원의 현재 위치한다 :

/company/config/spring-config.xml 

그것은 여기에 위치했다 :

/WEB-INF/company/config/spring-config.xml 
문제를 일으킨

. 나는 몇 번 전에 항아리를 확인했지만, 평범한 광경에 숨어있는 비열한 "/ WEB-INF"를 결코 알아 채지 못했습니다.

프로젝트를 제거하고 Eclipse (Maven pom.xml 파일을 통해)로 다시 가져 오는 것만으로는이 문제를 해결할 수 없습니다.

Eclipse 관련 .project, .classpath 및 .settings 파일을 수동으로 삭제해야했습니다. 내가 그 일을하고 프로젝트를 다시 가져올 때 모든 것이 수정되었습니다.

수업의 도덕은 : 항상 예외가 "파일을 찾을 수 없음"이라고 표시되면 리소스 경로를 확인하십시오.