首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我无法从相对位置导入bean定义。

我无法从相对位置导入bean定义。
EN

Stack Overflow用户
提问于 2020-09-02 12:53:39
回答 1查看 1.3K关注 0票数 1

当我在context-cfg.xml中导入applicationContext.xml时,我会得到下一个错误。

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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>

我的项目结构如下

有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-02 13:22:46

来自Maven的正式文档:Maven项目结构

在工件中生成源目录(即。( main和test),有一个目录用于java语言(在java语言下存在普通包层次结构),另一个目录用于资源目录(给定默认资源定义,该结构被复制到目标类路径)。

所以你有两个选择:

选项1 :

将文件的位置更改为Java资源

备选方案2 :

在本例中,您的代码在eclipse中运行良好,但是在maven构建过程中,您需要将资源文件夹添加到类路径中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63705956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档