Spring内部的war无法在内部jar文件中找到classpath资源

JBC*_*BCP 10 spring tomcat war classpath

我有一个像这样组织的项目:

core
  -- /src/main/resources/company/config/spring-config.xml
webapp
  -- /WEB-INF/applicationContext.xml
Run Code Online (Sandbox Code Playgroud)

webapp取决于我在部署时core.jar正确包含的内容WEB-INF/lib.

web.xml我有:

<param-value>
    /WEB-INF/applicationContext.xml
</param-value>
Run Code Online (Sandbox Code Playgroud)

applicationContext.xml我有:

<import resource="classpath:/company/config/spring-config.xml" />
Run Code Online (Sandbox Code Playgroud)

但是当我跑步时,我收到了这个错误:

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
Run Code Online (Sandbox Code Playgroud)

什么时候spring-config.xml在webapp中,一切正常.

我注意到/从堆栈跟踪中的一些错误中删除了前导,我想知道这是否与它有关.

另外,我(不幸的是)使用Spring 2.5,如果这很重要的话.

JBC*_*BCP 13

为了将来参考,我经过多次调试后想出了问题.事实证明Eclipse正在将我的"核心"库构建为jar,但是使用Web应用程序包布局,因此我的资源不在此处:

/company/config/spring-config.xml
Run Code Online (Sandbox Code Playgroud)

它位于这里:

/WEB-INF/company/config/spring-config.xml
Run Code Online (Sandbox Code Playgroud)

这引起了这个问题.我曾经几次检查过这个罐子,但是从来没有注意到偷偷摸摸的"/ WEB-INF"隐藏在视线之内.

删除项目并将其重新导入Eclipse(通过Maven pom.xml文件)还不足以解决问题.

我不得不手动删除特定于Eclipse的.project,.classpath和.settings文件.当我这样做并重新导入项目时,一切都得到了修复.

本课程的寓意是:当异常显示"找不到文件"时,总是检查资源路径.