当我在context-cfg.xml中导入applicationContext.xml时,我会得到下一个错误。
GRAVE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem:
Failed to import bean definitions from URL location [classpath:/context-cfg.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 [context-cfg.xml]; nested exception is java.io.FileNotFoundException: class path
resource [context-cfg.xml] cannot be opened because it does not existaplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<import resource="classpath:/context-cfg.xml" /> //this line throws the error
</beans>我的项目结构如下

有人能帮我吗?
发布于 2020-09-02 13:22:46
来自Maven的正式文档:Maven项目结构
在工件中生成源目录(即。( main和test),有一个目录用于java语言(在java语言下存在普通包层次结构),另一个目录用于资源目录(给定默认资源定义,该结构被复制到目标类路径)。
所以你有两个选择:
选项1 :
将文件的位置更改为Java资源
备选方案2 :
在本例中,您的代码在eclipse中运行良好,但是在maven构建过程中,您需要将资源文件夹添加到类路径中。
https://stackoverflow.com/questions/63705956
复制相似问题