类路径的资源我有这样的组织的项目:弹簧内部战争找不到一个内部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