ClassPathXmlApplicationContext错误,Spring框架

Abrakanoodle

关于Springs框架,我遇到了一个问题,导致服务器与数据库之间的通信不起作用。

我创建的项目是一个Spring项目,然后重构为Maven。

在代码的这一行: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("projectName/spring.xml");

我收到此错误: Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [projectName/spring.xml]; nested exception is java.io.FileNotFoundException: class path resource [projectName/spring.xml] cannot be opened because it does not exist

但是它确实存在。我已经尝试过解决该问题的解决方案,例如编写ClassPathXmlApplicationContext("spring.xml")但是,这没有帮助,因为从那时起,Spring会自动在src / main / resources文件夹中查找这对我不起作用,因为我的项目结构不允许我添加此文件夹并在其中放置XML文件。如果我尝试创建此文件夹,那么它将自动放入Java-resources文件夹中,并且Eclipse不允许我将XML放在其中。

这就是我的项目的样子:在此处输入图片描述

我有办法声明Spring在哪里寻找spring.xml文件吗?

贾维
new ClassPathXmlApplicationContext(this.getClass().getResource("/spring.xml").getPath())

试试上面的代码

希望能有所帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章