Java 我可以´;t从相对位置导入bean定义
在Java 我可以´;t从相对位置导入bean定义,java,spring,Java,Spring,在applicationContext.xml中导入context cfg.xml时,我遇到了下一个错误 GRAVE: Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath
applicationContext.xml
中导入context cfg.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 exist
aplicationContext.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>
//这行抛出错误
我的项目结构如下
有人能帮我吗?来自Maven的官方文档: 在生成工件的源目录(即main和test)中,有一个用于java语言的目录(在该目录下存在正常的包层次结构),还有一个用于资源(在给定默认资源定义的情况下复制到目标类路径的结构) 所以你有两个选择: 选项1: 将文件的位置更改为Java资源 选项2: 像这样的更改语句
在这种情况下,您的代码在eclipse env中可以正常工作,但是在maven构建过程中,您需要将资源文件夹添加到类路径中以使您的文件位于类路径中,您需要将其放置在java ressource目录中,或者更改如下行:@AyoubMk,我尝试过了,并且不断收到相同的错误。谢谢!!我已经阅读了文件,我决定选择选项1