我有带有 Spring 的 Maven 项目。我在类路径中有一个作为 jar 的后端项目(作为 Maven 依赖项添加)。后端项目再次使用 Spring 并拥有自己的 applicationContext.xml。在前端项目中,我有 applicationContext.xml,我想从后端访问应用程序上下文,如下所示:
<import resource="classpath:applicationContext.xml" />
但是我得到了:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:applicationContext.xml]
Offending resource: ServletContext resource [/WEB-INF/appContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
还尝试过:
<import resource="classpath*:applicationContext.xml" />
和
<import resource="classpath:/applicationContext.xml" />
最佳答案
如果我理解正确的话,你希望前端访问后端项目的applicationContext.xml。那么 classpath* 是正确的说法,并且您应该确保两个配置文件的命名空间相同。
例如,这种情况就行不通
前端:
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
后端:
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
关于java - 无法从类路径中的 jar 中找到 applicationContext.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14558640/