類路徑的資源我有這樣的組織的項目:彈簧內部戰爭找不到一個內部jar文件
core
-- /src/main/resources/company/config/spring-config.xml
webapp
-- /WEB-INF/applicationContext.xml
web應用程序依賴於core.jar
,這是在正確WEB-INF/lib
包括當我部署。
在web.xml
我:
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
而在applicationContext.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,如果這很重要。
刪除/從/company/config/spring-config.xml,然後檢查 – Satya
@Satya:謝謝,我試過了,我得到了同樣的結果。 – JBCP
@JBCP - 當你刪除前導斜槓時,它可能不起作用,因爲你有一些額外的問題,但它絕對不能用於前導斜槓。您可能還想閱讀本文,這可能有所幫助:http://blog.carbonfive.com/2007/05/17/using-classpath-vs-classpath-when-loading-spring-resources/ – GreyBeardedGeek